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