Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(937)

Side by Side Diff: chrome/browser/extensions/api/runtime/chrome_runtime_api_delegate.h

Issue 1887253002: Rate limit programmatic update checks for extensions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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_RUNTIME_CHROME_RUNTIME_API_DELEGATE_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_RUNTIME_CHROME_RUNTIME_API_DELEGATE_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_RUNTIME_CHROME_RUNTIME_API_DELEGATE_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_RUNTIME_CHROME_RUNTIME_API_DELEGATE_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string>
10 #include <utility>
9 #include <vector> 11 #include <vector>
Devlin 2016/04/15 17:57:37 nit: don't need this anymore
asargent_no_longer_on_chrome 2016/04/19 17:56:53 Done.
10 12
11 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/scoped_observer.h"
12 #include "content/public/browser/notification_observer.h" 15 #include "content/public/browser/notification_observer.h"
13 #include "content/public/browser/notification_registrar.h" 16 #include "content/public/browser/notification_registrar.h"
14 #include "extensions/browser/api/runtime/runtime_api.h" 17 #include "extensions/browser/api/runtime/runtime_api.h"
15 #include "extensions/browser/api/runtime/runtime_api_delegate.h" 18 #include "extensions/browser/api/runtime/runtime_api_delegate.h"
19 #include "extensions/browser/extension_registry_observer.h"
16 20
17 namespace base { 21 namespace base {
22 class TickClock;
18 class TimeTicks; 23 class TimeTicks;
19 } 24 }
20 25
21 namespace content { 26 namespace content {
22 class BrowserContext; 27 class BrowserContext;
23 class NotificationDetails; 28 class NotificationDetails;
24 class NotificationSource; 29 class NotificationSource;
25 } 30 }
26 31
27 namespace extensions { 32 namespace extensions {
33 class ExtensionRegistry;
28 class RuntimeAPI; 34 class RuntimeAPI;
29 class UpdateObserver; 35 class UpdateObserver;
30 } 36 }
31 37
32 class ChromeRuntimeAPIDelegate : public extensions::RuntimeAPIDelegate, 38 class ChromeRuntimeAPIDelegate : public extensions::RuntimeAPIDelegate,
33 public content::NotificationObserver { 39 public content::NotificationObserver,
40 public extensions::ExtensionRegistryObserver {
34 public: 41 public:
35 explicit ChromeRuntimeAPIDelegate(content::BrowserContext* context); 42 explicit ChromeRuntimeAPIDelegate(content::BrowserContext* context);
36 ~ChromeRuntimeAPIDelegate() override; 43 ~ChromeRuntimeAPIDelegate() override;
37 44
45 // Sets a custom TickClock to use in tests.
46 static void set_tick_clock_for_tests(base::TickClock* clock);
47
38 private: 48 private:
39 friend class extensions::RuntimeAPI; 49 friend class extensions::RuntimeAPI;
40 50
41 // extensions::RuntimeAPIDelegate implementation. 51 // extensions::RuntimeAPIDelegate implementation.
42 void AddUpdateObserver(extensions::UpdateObserver* observer) override; 52 void AddUpdateObserver(extensions::UpdateObserver* observer) override;
43 void RemoveUpdateObserver(extensions::UpdateObserver* observer) override; 53 void RemoveUpdateObserver(extensions::UpdateObserver* observer) override;
44 base::Version GetPreviousExtensionVersion( 54 base::Version GetPreviousExtensionVersion(
45 const extensions::Extension* extension) override; 55 const extensions::Extension* extension) override;
46 void ReloadExtension(const std::string& extension_id) override; 56 void ReloadExtension(const std::string& extension_id) override;
47 bool CheckForUpdates(const std::string& extension_id, 57 bool CheckForUpdates(const std::string& extension_id,
48 const UpdateCheckCallback& callback) override; 58 const UpdateCheckCallback& callback) override;
49 void OpenURL(const GURL& uninstall_url) override; 59 void OpenURL(const GURL& uninstall_url) override;
50 bool GetPlatformInfo(extensions::api::runtime::PlatformInfo* info) override; 60 bool GetPlatformInfo(extensions::api::runtime::PlatformInfo* info) override;
51 bool RestartDevice(std::string* error_message) override; 61 bool RestartDevice(std::string* error_message) override;
52 bool OpenOptionsPage(const extensions::Extension* extension) override; 62 bool OpenOptionsPage(const extensions::Extension* extension) override;
53 63
54 // content::NotificationObserver implementation. 64 // content::NotificationObserver implementation.
55 void Observe(int type, 65 void Observe(int type,
56 const content::NotificationSource& source, 66 const content::NotificationSource& source,
57 const content::NotificationDetails& details) override; 67 const content::NotificationDetails& details) override;
58 68
69 // ExtensionRegistryObserver implementation.
70 void OnExtensionInstalled(content::BrowserContext* browser_context,
71 const extensions::Extension* extension,
72 bool is_update) override;
73
59 void UpdateCheckComplete(const std::string& extension_id); 74 void UpdateCheckComplete(const std::string& extension_id);
60 void CallUpdateCallbacks(const std::string& extension_id, 75 void CallUpdateCallbacks(const std::string& extension_id,
61 const UpdateCheckResult& result); 76 const UpdateCheckResult& result);
62 77
63 content::BrowserContext* browser_context_; 78 content::BrowserContext* browser_context_;
64 79
65 content::NotificationRegistrar registrar_; 80 content::NotificationRegistrar registrar_;
66 81
67 // Whether the API registered with the ExtensionService to receive 82 // Whether the API registered with the ExtensionService to receive
68 // update notifications. 83 // update notifications.
69 bool registered_for_updates_; 84 bool registered_for_updates_;
70 85
71 // Map to prevent extensions from getting stuck in reload loops. Maps 86 // Map to prevent extensions from getting stuck in reload loops. Maps
72 // extension id to the last time it was reloaded and the number of times 87 // extension id to the last time it was reloaded and the number of times
73 // it was reloaded with not enough time in between reloads. 88 // it was reloaded with not enough time in between reloads.
74 std::map<std::string, std::pair<base::TimeTicks, int> > last_reload_time_; 89 std::map<std::string, std::pair<base::TimeTicks, int> > last_reload_time_;
75 90
76 // Pending update checks. 91 // Information about update checks, keyed by extension id.
77 typedef std::vector<UpdateCheckCallback> UpdateCallbackList; 92 struct UpdateCheckInfo;
78 typedef std::map<std::string, UpdateCallbackList> UpdateCallbackMap; 93 std::map<std::string, UpdateCheckInfo> update_check_info_;
79 UpdateCallbackMap pending_update_checks_; 94
95 ScopedObserver<extensions::ExtensionRegistry,
96 extensions::ExtensionRegistryObserver>
97 extension_registry_observer_;
80 98
81 private: 99 private:
Devlin 2016/04/15 17:57:37 drive-by: remove
asargent_no_longer_on_chrome 2016/04/19 17:56:53 Done.
82 DISALLOW_COPY_AND_ASSIGN(ChromeRuntimeAPIDelegate); 100 DISALLOW_COPY_AND_ASSIGN(ChromeRuntimeAPIDelegate);
83 }; 101 };
84 102
85 #endif // CHROME_BROWSER_EXTENSIONS_API_RUNTIME_CHROME_RUNTIME_API_DELEGATE_H_ 103 #endif // CHROME_BROWSER_EXTENSIONS_API_RUNTIME_CHROME_RUNTIME_API_DELEGATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698