| 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/values.h" | 13 #include "base/values.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 }; | 30 }; |
| 30 | 31 |
| 31 extern const char kSrcIdKey[]; | 32 extern const char kSrcIdKey[]; |
| 32 | 33 |
| 33 // TODO(miket): It's possible that we'll further refactor these new classes in | 34 // TODO(miket): It's possible that we'll further refactor these new classes in |
| 34 // light of some changes that mihaip has suggested. The names might change, | 35 // light of some changes that mihaip has suggested. The names might change, |
| 35 // too: | 36 // too: |
| 36 // | 37 // |
| 37 // IOResource | 38 // IOResource |
| 38 // IOResourceExtensionFunction | 39 // IOResourceExtensionFunction |
| (...skipping 13 matching lines...) Expand all Loading... |
| 52 virtual void OnConnectComplete(int result_code); | 53 virtual void OnConnectComplete(int result_code); |
| 53 | 54 |
| 54 // Takes ownership of data. | 55 // Takes ownership of data. |
| 55 virtual void OnDataRead(int result_code, | 56 virtual void OnDataRead(int result_code, |
| 56 base::ListValue* data, | 57 base::ListValue* data, |
| 57 const std::string& address, | 58 const std::string& address, |
| 58 int port); | 59 int port); |
| 59 | 60 |
| 60 virtual void OnWriteComplete(int result_code); | 61 virtual void OnWriteComplete(int result_code); |
| 61 | 62 |
| 63 virtual void OnTransferComplete(int result_code, base::ListValue* data); |
| 64 |
| 62 static std::string APIResourceEventTypeToString( | 65 static std::string APIResourceEventTypeToString( |
| 63 APIResourceEventType event_type); | 66 APIResourceEventType event_type); |
| 64 | 67 |
| 65 private: | 68 private: |
| 66 friend class base::RefCountedThreadSafe<APIResourceEventNotifier>; | 69 friend class base::RefCountedThreadSafe<APIResourceEventNotifier>; |
| 67 friend class MockAPIResourceEventNotifier; | 70 friend class MockAPIResourceEventNotifier; |
| 68 | 71 |
| 69 virtual ~APIResourceEventNotifier(); | 72 virtual ~APIResourceEventNotifier(); |
| 70 | 73 |
| 71 void DispatchEvent(DictionaryValue* event); | 74 void DispatchEvent(const std::string &extension, DictionaryValue* event); |
| 72 void DispatchEventOnUIThread(DictionaryValue* event); | 75 void DispatchEventOnUIThread(const std::string& extension, |
| 76 DictionaryValue* event); |
| 73 DictionaryValue* CreateAPIResourceEvent(APIResourceEventType event_type); | 77 DictionaryValue* CreateAPIResourceEvent(APIResourceEventType event_type); |
| 74 | 78 |
| 75 void SendEventWithResultCode(APIResourceEventType event_type, | 79 void SendEventWithResultCode(const std::string& extension, |
| 80 APIResourceEventType event_type, |
| 76 int result_code); | 81 int result_code); |
| 77 | 82 |
| 78 ExtensionEventRouter* router_; | 83 ExtensionEventRouter* router_; |
| 79 Profile* profile_; | 84 Profile* profile_; |
| 80 std::string src_extension_id_; | 85 std::string src_extension_id_; |
| 81 int src_id_; | 86 int src_id_; |
| 82 GURL src_url_; | 87 GURL src_url_; |
| 83 | 88 |
| 84 DISALLOW_COPY_AND_ASSIGN(APIResourceEventNotifier); | 89 DISALLOW_COPY_AND_ASSIGN(APIResourceEventNotifier); |
| 85 }; | 90 }; |
| 86 | 91 |
| 87 } // namespace extensions | 92 } // namespace extensions |
| 88 | 93 |
| 89 #endif // CHROME_BROWSER_EXTENSIONS_API_API_RESOURCE_EVENT_NOTIFIER_H_ | 94 #endif // CHROME_BROWSER_EXTENSIONS_API_API_RESOURCE_EVENT_NOTIFIER_H_ |
| OLD | NEW |