Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: chrome/browser/extensions/api/api_resource_event_notifier.h

Issue 10777003: Refactor APIResourceController to ProfileKeyedService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge/antony/fix build. Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_API_RESOURCE_EVENT_NOTIFIER_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_API_RESOURCE_EVENT_NOTIFIER_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_API_RESOURCE_EVENT_NOTIFIER_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_API_RESOURCE_EVENT_NOTIFIER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/usb/usb_device.h" 13 #include "chrome/browser/usb/usb_device.h"
14 #include "googleurl/src/gurl.h" 14 #include "googleurl/src/gurl.h"
15 15
16 class ExtensionEventRouter; 16 class ExtensionEventRouter;
17 class Profile; 17 class Profile;
18 18
19 namespace base { 19 namespace base {
20 class ListValue; 20 class ListValue;
21 } 21 }
22 22
23 namespace extensions { 23 namespace extensions {
24 24
25 enum APIResourceEventType { 25 enum ApiResourceEventType {
26 API_RESOURCE_EVENT_CONNECT_COMPLETE, 26 API_RESOURCE_EVENT_CONNECT_COMPLETE,
27 API_RESOURCE_EVENT_DATA_READ, 27 API_RESOURCE_EVENT_DATA_READ,
28 API_RESOURCE_EVENT_WRITE_COMPLETE, 28 API_RESOURCE_EVENT_WRITE_COMPLETE,
29 API_RESOURCE_EVENT_TRANSFER_COMPLETE, 29 API_RESOURCE_EVENT_TRANSFER_COMPLETE,
30 }; 30 };
31 31
32 extern const char kSrcIdKey[]; 32 extern const char kSrcIdKey[];
33 33
34 // TODO(miket): It's possible that we'll further refactor these new classes in 34 // ApiResourceEventNotifier knows how to send an event to a specific app's
35 // light of some changes that mihaip has suggested. The names might change, 35 // onEvent handler.
36 // too: 36 class ApiResourceEventNotifier
37 // 37 : public base::RefCountedThreadSafe<ApiResourceEventNotifier> {
38 // IOResource
39 // IOResourceExtensionFunction
40 // IOResourceEventNotifier
41 // IOResourceController
42
43 // APIResourceEventNotifier knows how to send an event to a specific app's
44 // onEvent handler. It handles all platform-API events.
45 class APIResourceEventNotifier
46 : public base::RefCountedThreadSafe<APIResourceEventNotifier> {
47 public: 38 public:
48 APIResourceEventNotifier(ExtensionEventRouter* router, 39 ApiResourceEventNotifier(ExtensionEventRouter* router,
49 Profile* profile, 40 Profile* profile,
50 const std::string& src_extension_id, int src_id, 41 const std::string& src_extension_id, int src_id,
51 const GURL& src_url); 42 const GURL& src_url);
52 43
53 virtual void OnConnectComplete(int result_code); 44 virtual void OnConnectComplete(int result_code);
54 45
55 // Takes ownership of data. 46 // Takes ownership of data.
56 virtual void OnDataRead(int result_code, 47 virtual void OnDataRead(int result_code,
57 base::ListValue* data, 48 base::ListValue* data,
58 const std::string& address, 49 const std::string& address,
59 int port); 50 int port);
60 51
61 virtual void OnWriteComplete(int result_code); 52 virtual void OnWriteComplete(int result_code);
62 53
63 virtual void OnTransferComplete(UsbTransferStatus status, 54 virtual void OnTransferComplete(UsbTransferStatus status,
64 const std::string& error, 55 const std::string& error,
65 base::BinaryValue* data); 56 base::BinaryValue* data);
66 57
67 static std::string APIResourceEventTypeToString( 58 static std::string ApiResourceEventTypeToString(
68 APIResourceEventType event_type); 59 ApiResourceEventType event_type);
69 60
70 private: 61 private:
71 friend class base::RefCountedThreadSafe<APIResourceEventNotifier>; 62 friend class base::RefCountedThreadSafe<ApiResourceEventNotifier>;
72 friend class MockAPIResourceEventNotifier; 63 friend class MockApiResourceEventNotifier;
73 64
74 virtual ~APIResourceEventNotifier(); 65 virtual ~ApiResourceEventNotifier();
75 66
76 void DispatchEvent(const std::string &extension, DictionaryValue* event); 67 void DispatchEvent(const std::string &extension, DictionaryValue* event);
77 void DispatchEventOnUIThread(const std::string& extension, 68 void DispatchEventOnUIThread(const std::string& extension,
78 DictionaryValue* event); 69 DictionaryValue* event);
79 DictionaryValue* CreateAPIResourceEvent(APIResourceEventType event_type); 70 DictionaryValue* CreateApiResourceEvent(ApiResourceEventType event_type);
80 71
81 void SendEventWithResultCode(const std::string& extension, 72 void SendEventWithResultCode(const std::string& extension,
82 APIResourceEventType event_type, 73 ApiResourceEventType event_type,
83 int result_code); 74 int result_code);
84 75
85 ExtensionEventRouter* router_; 76 ExtensionEventRouter* router_;
86 Profile* profile_; 77 Profile* profile_;
87 std::string src_extension_id_; 78 std::string src_extension_id_;
88 int src_id_; 79 int src_id_;
89 GURL src_url_; 80 GURL src_url_;
90 81
91 DISALLOW_COPY_AND_ASSIGN(APIResourceEventNotifier); 82 DISALLOW_COPY_AND_ASSIGN(ApiResourceEventNotifier);
92 }; 83 };
93 84
94 } // namespace extensions 85 } // namespace extensions
95 86
96 #endif // CHROME_BROWSER_EXTENSIONS_API_API_RESOURCE_EVENT_NOTIFIER_H_ 87 #endif // CHROME_BROWSER_EXTENSIONS_API_API_RESOURCE_EVENT_NOTIFIER_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/api_resource_controller.cc ('k') | chrome/browser/extensions/api/api_resource_event_notifier.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698