| 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 <memory> | |
| 10 #include <string> | |
| 11 | |
| 12 #include "base/macros.h" | |
| 13 #include "base/scoped_observer.h" | |
| 14 #include "chrome/browser/extensions/install_observer.h" | |
| 15 #include "chrome/common/extensions/api/webstore/webstore_api_constants.h" | |
| 16 #include "extensions/browser/browser_context_keyed_api_factory.h" | |
| 17 #include "extensions/browser/event_router.h" | |
| 18 | |
| 19 namespace base { | |
| 20 class ListValue; | |
| 21 } | |
| 22 | |
| 23 namespace content { | |
| 24 class BrowserContext; | |
| 25 } | |
| 26 | |
| 27 namespace IPC { | |
| 28 class Sender; | |
| 29 } | |
| 30 | |
| 31 namespace extensions { | |
| 32 class InstallTracker; | |
| 33 | |
| 34 class WebstoreAPI : public BrowserContextKeyedAPI, | |
| 35 public InstallObserver { | |
| 36 public: | |
| 37 explicit WebstoreAPI(content::BrowserContext* browser_context); | |
| 38 ~WebstoreAPI() override; | |
| 39 | |
| 40 static WebstoreAPI* Get(content::BrowserContext* browser_context); | |
| 41 | |
| 42 // Called whenever an inline extension install is started. Examines | |
| 43 // |listener_mask| to determine if a download progress or install | |
| 44 // stage listener should be added. | |
| 45 // |routing_id| refers to the id to which we send any return messages; | |
| 46 // |ipc_sender| is the sender through which we send them (typically this | |
| 47 // is the TabHelper which started the inline install). | |
| 48 void OnInlineInstallStart(int routing_id, | |
| 49 IPC::Sender* ipc_sender, | |
| 50 const std::string& extension_id, | |
| 51 int listener_mask); | |
| 52 | |
| 53 // Called when an inline extension install finishes. Removes any listeners | |
| 54 // related to the |routing_id|-|extension_id| pair. | |
| 55 void OnInlineInstallFinished(int routing_id, const std::string& extension_id); | |
| 56 | |
| 57 // BrowserContextKeyedAPI implementation. | |
| 58 static BrowserContextKeyedAPIFactory<WebstoreAPI>* GetFactoryInstance(); | |
| 59 | |
| 60 private: | |
| 61 friend class BrowserContextKeyedAPIFactory<WebstoreAPI>; | |
| 62 | |
| 63 // A simple struct to hold our listeners' information for each observed | |
| 64 // install. | |
| 65 struct ObservedInstallInfo; | |
| 66 typedef std::list<ObservedInstallInfo> ObservedInstallInfoList; | |
| 67 | |
| 68 // Sends an installation stage update message if we are observing | |
| 69 // the extension's install. | |
| 70 void SendInstallMessageIfObserved(const std::string& extension_id, | |
| 71 api::webstore::InstallStage install_stage); | |
| 72 | |
| 73 // Removes listeners for the given |extension_id|-|routing_id| pair from | |
| 74 // |listeners|. | |
| 75 void RemoveListeners(int routing_id, | |
| 76 const std::string& extension_id, | |
| 77 ObservedInstallInfoList* listeners); | |
| 78 | |
| 79 // InstallObserver implementation. | |
| 80 void OnBeginExtensionDownload(const std::string& extension_id) override; | |
| 81 void OnDownloadProgress(const std::string& extension_id, | |
| 82 int percent_downloaded) override; | |
| 83 void OnBeginCrxInstall(const std::string& extension_id) override; | |
| 84 void OnShutdown() override; | |
| 85 | |
| 86 // BrowserContextKeyedService implementation. | |
| 87 void Shutdown() override; | |
| 88 | |
| 89 // BrowserContextKeyedAPI implementation. | |
| 90 static const char* service_name() { return "WebstoreAPI"; } | |
| 91 static const bool kServiceIsNULLWhileTesting = true; | |
| 92 | |
| 93 ObservedInstallInfoList download_progress_listeners_; | |
| 94 ObservedInstallInfoList install_stage_listeners_; | |
| 95 content::BrowserContext* browser_context_; | |
| 96 std::unique_ptr<ScopedObserver<InstallTracker, InstallObserver>> | |
| 97 install_observer_; | |
| 98 | |
| 99 DISALLOW_COPY_AND_ASSIGN(WebstoreAPI); | |
| 100 }; | |
| 101 | |
| 102 } // namespace extensions | |
| 103 | |
| 104 #endif // CHROME_BROWSER_EXTENSIONS_API_WEBSTORE_WEBSTORE_API_H_ | |
| OLD | NEW |