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