Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/plugins/plugins_resource_service.h" | 5 #include "chrome/browser/plugins/plugins_resource_service.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/prefs/pref_registry_simple.h" | 8 #include "base/prefs/pref_registry_simple.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "chrome/browser/plugins/plugin_finder.h" | 10 #include "chrome/browser/plugins/plugin_finder.h" |
| 11 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
| 12 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
| 13 #include "url/gurl.h" | 13 #include "url/gurl.h" |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 // Delay on first fetch so we don't interfere with startup. | 17 // Delay on first fetch so we don't interfere with startup. |
| 18 const int kStartResourceFetchDelayMs = 60 * 1000; | 18 const int kStartResourceFetchDelayMs = 60 * 1000; |
| 19 | 19 |
| 20 // Delay between calls to update the cache 1 day and 2 minutes in testing mode. | 20 // Delay between calls to update the cache 1 day and 2 minutes in testing mode. |
| 21 const int kCacheUpdateDelayMs = 24 * 60 * 60 * 1000; | 21 const int kCacheUpdateDelayMs = 24 * 60 * 60 * 1000; |
| 22 const int kTestCacheUpdateDelayMs = 2 * 60 * 1000; | 22 const int kTestCacheUpdateDelayMs = 2 * 60 * 1000; |
| 23 | 23 |
| 24 const char kPluginsServerUrl[] = | 24 const char kPluginsServerUrl[] = |
| 25 "https://www.gstatic.com/chrome/config/plugins_2/"; | 25 "https://www.gstatic.com/chrome/config/plugins_2/"; |
| 26 | 26 |
| 27 bool IsTest() { | |
| 28 return base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 29 switches::kPluginsMetadataServerURL); | |
| 30 } | |
| 31 | |
| 32 GURL GetPluginsServerURL() { | 27 GURL GetPluginsServerURL() { |
| 33 std::string filename; | 28 std::string filename; |
| 34 #if defined(OS_WIN) | 29 #if defined(OS_WIN) |
| 35 filename = "plugins_win.json"; | 30 filename = "plugins_win.json"; |
| 36 #elif defined(OS_LINUX) | 31 #elif defined(OS_LINUX) |
| 37 filename = "plugins_linux.json"; | 32 filename = "plugins_linux.json"; |
| 38 #elif defined(OS_MACOSX) | 33 #elif defined(OS_MACOSX) |
| 39 filename = "plugins_mac.json"; | 34 filename = "plugins_mac.json"; |
| 40 #else | 35 #else |
| 41 #error Unknown platform | 36 #error Unknown platform |
| 42 #endif | 37 #endif |
| 43 | 38 |
| 44 std::string test_url = | 39 std::string test_url = |
| 45 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 40 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 46 switches::kPluginsMetadataServerURL); | 41 switches::kPluginsMetadataServerURL); |
|
Bernhard Bauer
2015/01/06 09:26:22
Heh, I think you built this change on a platform t
MRV
2015/01/06 09:56:27
Done.
| |
| 47 return GURL(IsTest() ? test_url : kPluginsServerUrl + filename); | 42 return GURL(kPluginsServerUrl + filename); |
| 48 } | 43 } |
| 49 | 44 |
| 50 int GetCacheUpdateDelay() { | 45 int GetCacheUpdateDelay() { |
|
Bernhard Bauer
2015/01/06 09:26:22
This can be inlined now.
MRV
2015/01/06 09:56:27
Done.
Bernhard Bauer
2015/01/06 09:59:26
I meant inlined as a transformation of the source
MRV
2015/01/06 11:07:11
Done.
| |
| 51 return IsTest() ? kTestCacheUpdateDelayMs : kCacheUpdateDelayMs; | 46 return kCacheUpdateDelayMs; |
| 52 } | 47 } |
| 53 | 48 |
| 54 } // namespace | 49 } // namespace |
| 55 | 50 |
| 56 PluginsResourceService::PluginsResourceService(PrefService* local_state) | 51 PluginsResourceService::PluginsResourceService(PrefService* local_state) |
| 57 : WebResourceService(local_state, | 52 : WebResourceService(local_state, |
| 58 GetPluginsServerURL(), | 53 GetPluginsServerURL(), |
| 59 false, | 54 false, |
| 60 prefs::kPluginsResourceCacheUpdate, | 55 prefs::kPluginsResourceCacheUpdate, |
| 61 kStartResourceFetchDelayMs, | 56 kStartResourceFetchDelayMs, |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 76 void PluginsResourceService::RegisterPrefs(PrefRegistrySimple* registry) { | 71 void PluginsResourceService::RegisterPrefs(PrefRegistrySimple* registry) { |
| 77 registry->RegisterDictionaryPref(prefs::kPluginsMetadata, | 72 registry->RegisterDictionaryPref(prefs::kPluginsMetadata, |
| 78 new base::DictionaryValue()); | 73 new base::DictionaryValue()); |
| 79 registry->RegisterStringPref(prefs::kPluginsResourceCacheUpdate, "0"); | 74 registry->RegisterStringPref(prefs::kPluginsResourceCacheUpdate, "0"); |
| 80 } | 75 } |
| 81 | 76 |
| 82 void PluginsResourceService::Unpack(const base::DictionaryValue& parsed_json) { | 77 void PluginsResourceService::Unpack(const base::DictionaryValue& parsed_json) { |
| 83 prefs_->Set(prefs::kPluginsMetadata, parsed_json); | 78 prefs_->Set(prefs::kPluginsMetadata, parsed_json); |
| 84 PluginFinder::GetInstance()->ReinitializePlugins(&parsed_json); | 79 PluginFinder::GetInstance()->ReinitializePlugins(&parsed_json); |
| 85 } | 80 } |
| OLD | NEW |