summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/extension_io_event_router.h
blob: 1a278902db4b6068b8d69e591a1110c8b400af39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_IO_EVENT_ROUTER_H_
#define CHROME_BROWSER_EXTENSIONS_EXTENSION_IO_EVENT_ROUTER_H_
#pragma once

#include <string>

#include "base/ref_counted.h"

class Profile;

// For now, this just forwards events from the IO thread to the
// ExtensionEventRouter on the UI thread.
// TODO(mpcomplete): eventually I want this to have its own copy of the event
// listeners so it can bypass the jump to the UI thread.
class ExtensionIOEventRouter
    : public base::RefCountedThreadSafe<ExtensionIOEventRouter> {
 public:
  explicit ExtensionIOEventRouter(Profile* profile);
  ~ExtensionIOEventRouter();

  void DestroyingProfile() { profile_ = NULL; }

  // Dispatch the named event to every extension listening to that event.
  void DispatchEvent(const std::string& event_name,
                     const std::string& event_args) const;

 private:
  Profile* profile_;

  void DispatchEventOnUIThread(const std::string& event_name,
                               const std::string& event_args) const;

  DISALLOW_COPY_AND_ASSIGN(ExtensionIOEventRouter);
};

#endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_IO_EVENT_ROUTER_H_