OLD | NEW |
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 Profile; | 16 class Profile; |
17 | 17 |
18 namespace base { | 18 namespace base { |
19 class ListValue; | 19 class ListValue; |
20 } | 20 } |
21 | 21 |
22 namespace extensions { | 22 namespace extensions { |
23 class EventRouter; | 23 class EventRouter; |
24 | 24 |
25 enum ApiResourceEventType { | 25 enum ApiResourceEventType { |
26 API_RESOURCE_EVENT_CONNECT_COMPLETE, | |
27 API_RESOURCE_EVENT_DATA_READ, | |
28 API_RESOURCE_EVENT_WRITE_COMPLETE, | |
29 API_RESOURCE_EVENT_TRANSFER_COMPLETE, | 26 API_RESOURCE_EVENT_TRANSFER_COMPLETE, |
30 }; | 27 }; |
31 | 28 |
32 extern const char kSrcIdKey[]; | 29 extern const char kSrcIdKey[]; |
33 | 30 |
34 // ApiResourceEventNotifier knows how to send an event to a specific app's | 31 // ApiResourceEventNotifier knows how to send an event to a specific app's |
35 // onEvent handler. | 32 // onEvent handler. |
36 class ApiResourceEventNotifier | 33 class ApiResourceEventNotifier |
37 : public base::RefCountedThreadSafe<ApiResourceEventNotifier> { | 34 : public base::RefCountedThreadSafe<ApiResourceEventNotifier> { |
38 public: | 35 public: |
39 ApiResourceEventNotifier(EventRouter* router, | 36 ApiResourceEventNotifier(EventRouter* router, |
40 Profile* profile, | 37 Profile* profile, |
41 const std::string& src_extension_id, int src_id, | 38 const std::string& src_extension_id, int src_id, |
42 const GURL& src_url); | 39 const GURL& src_url); |
43 | 40 |
44 virtual void OnConnectComplete(int result_code); | |
45 | |
46 // Takes ownership of data. | |
47 virtual void OnDataRead(int result_code, | |
48 base::ListValue* data, | |
49 const std::string& address, | |
50 int port); | |
51 | |
52 virtual void OnWriteComplete(int result_code); | |
53 | |
54 virtual void OnTransferComplete(UsbTransferStatus status, | 41 virtual void OnTransferComplete(UsbTransferStatus status, |
55 const std::string& error, | 42 const std::string& error, |
56 base::BinaryValue* data); | 43 base::BinaryValue* data); |
57 | 44 |
58 static std::string ApiResourceEventTypeToString( | 45 static std::string ApiResourceEventTypeToString( |
59 ApiResourceEventType event_type); | 46 ApiResourceEventType event_type); |
60 | 47 |
61 private: | 48 private: |
62 friend class base::RefCountedThreadSafe<ApiResourceEventNotifier>; | 49 friend class base::RefCountedThreadSafe<ApiResourceEventNotifier>; |
63 friend class MockApiResourceEventNotifier; | 50 friend class MockApiResourceEventNotifier; |
(...skipping 14 matching lines...) Expand all Loading... |
78 std::string src_extension_id_; | 65 std::string src_extension_id_; |
79 int src_id_; | 66 int src_id_; |
80 GURL src_url_; | 67 GURL src_url_; |
81 | 68 |
82 DISALLOW_COPY_AND_ASSIGN(ApiResourceEventNotifier); | 69 DISALLOW_COPY_AND_ASSIGN(ApiResourceEventNotifier); |
83 }; | 70 }; |
84 | 71 |
85 } // namespace extensions | 72 } // namespace extensions |
86 | 73 |
87 #endif // CHROME_BROWSER_EXTENSIONS_API_API_RESOURCE_EVENT_NOTIFIER_H_ | 74 #endif // CHROME_BROWSER_EXTENSIONS_API_API_RESOURCE_EVENT_NOTIFIER_H_ |
OLD | NEW |