OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_WEBSTORE_WEBSTORE_API_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_WEBSTORE_WEBSTORE_API_H_ |
| 7 |
| 8 #include <list> |
| 9 #include <string> |
| 10 |
| 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "chrome/browser/extensions/api/profile_keyed_api_factory.h" |
| 13 #include "chrome/browser/extensions/install_observer.h" |
| 14 #include "extensions/browser/event_router.h" |
| 15 |
| 16 class Profile; |
| 17 |
| 18 namespace base { |
| 19 class ListValue; |
| 20 } |
| 21 |
| 22 namespace ipc { |
| 23 class Sender; |
| 24 } |
| 25 |
| 26 namespace extensions { |
| 27 |
| 28 class ListenerSet; |
| 29 |
| 30 class WebstoreAPI : public ProfileKeyedAPI, public InstallObserver { |
| 31 public: |
| 32 explicit WebstoreAPI(Profile* profile); |
| 33 virtual ~WebstoreAPI(); |
| 34 |
| 35 static WebstoreAPI* Get(Profile* profile); |
| 36 |
| 37 // Called whenever an inline extension install is started. Examines |
| 38 // |listener_mask| to determine if a download progress or install |
| 39 // stage listener should be added. |
| 40 // |routing_id| refers to the id to which we send any return messages; |
| 41 // |ipc_sender| is the sender through which we send them (typically this |
| 42 // is the TabHelper which started the inline install). |
| 43 void OnInlineInstallStart(int routing_id, |
| 44 IPC::Sender* ipc_sender, |
| 45 const std::string& extension_id, |
| 46 int listener_mask); |
| 47 |
| 48 // Called when an inline extension install finishes. Removes any listeners |
| 49 // related to the |routing_id|-|extension_id| pair. |
| 50 void OnInlineInstallFinished(int routing_id, const std::string& extension_id); |
| 51 |
| 52 // InstallObserver implementation. |
| 53 virtual void OnBeginExtensionDownload(const std::string& extension_id) |
| 54 OVERRIDE; |
| 55 virtual void OnDownloadProgress(const std::string& extension_id, |
| 56 int percent_downloaded) OVERRIDE; |
| 57 virtual void OnBeginCrxInstall(const std::string& extension_id) OVERRIDE; |
| 58 |
| 59 // BrowserContextKeyedService implementation. |
| 60 virtual void Shutdown() OVERRIDE; |
| 61 |
| 62 // ProfileKeyedAPI implementation. |
| 63 static ProfileKeyedAPIFactory<WebstoreAPI>* GetFactoryInstance(); |
| 64 |
| 65 private: |
| 66 friend class ProfileKeyedAPIFactory<WebstoreAPI>; |
| 67 |
| 68 // A simple struct to hold our listeners' information for each observed |
| 69 // install. |
| 70 struct ObservedInstallInfo { |
| 71 ObservedInstallInfo(int routing_id, |
| 72 const std::string& extension_id, |
| 73 IPC::Sender* ipc_sender); |
| 74 ~ObservedInstallInfo(); |
| 75 |
| 76 int routing_id; |
| 77 std::string extension_id; |
| 78 IPC::Sender* ipc_sender; |
| 79 }; |
| 80 typedef std::list<ObservedInstallInfo> ObservedInstallInfoList; |
| 81 |
| 82 // Sends an installation stage update message if we are observing |
| 83 // the extension's install. |
| 84 void SendInstallMessageIfObserved(const std::string& extension_id, |
| 85 const std::string& install_stage); |
| 86 |
| 87 // Removes listeners for the given |extension_id|-|routing_id| pair from |
| 88 // |listeners|. |
| 89 void RemoveListeners(int routing_id, |
| 90 const std::string& extension_id, |
| 91 ObservedInstallInfoList* listeners); |
| 92 |
| 93 // ProfileKeyedAPI implementation. |
| 94 static const char* service_name() { return "WebstoreAPI"; } |
| 95 static const bool kServiceIsNULLWhileTesting = true; |
| 96 |
| 97 std::list<ObservedInstallInfo> download_progress_listeners_; |
| 98 std::list<ObservedInstallInfo> install_stage_listeners_; |
| 99 Profile* profile_; |
| 100 |
| 101 DISALLOW_COPY_AND_ASSIGN(WebstoreAPI); |
| 102 }; |
| 103 |
| 104 } // namespace extensions |
| 105 |
| 106 #endif // CHROME_BROWSER_EXTENSIONS_API_WEBSTORE_WEBSTORE_API_H_ |
OLD | NEW |