OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/web_resource/plugins_resource_service.h" | |
6 | |
7 #include "base/command_line.h" | |
8 #include "chrome/browser/plugins/plugin_finder.h" | |
9 #include "chrome/browser/prefs/pref_registry_simple.h" | |
10 #include "chrome/browser/prefs/pref_service.h" | |
11 #include "chrome/common/chrome_switches.h" | |
12 #include "chrome/common/pref_names.h" | |
13 #include "googleurl/src/gurl.h" | |
14 | |
15 namespace { | |
16 | |
17 // Delay on first fetch so we don't interfere with startup. | |
18 const int kStartResourceFetchDelayMs = 60 * 1000; | |
19 | |
20 // Delay between calls to update the cache 1 day and 2 minutes in testing mode. | |
21 const int kCacheUpdateDelayMs = 24 * 60 * 60 * 1000; | |
22 const int kTestCacheUpdateDelayMs = 2 * 60 * 1000; | |
23 | |
24 const char kPluginsServerUrl[] = | |
25 "https://www.gstatic.com/chrome/config/plugins_2/"; | |
26 | |
27 bool IsTest() { | |
28 return CommandLine::ForCurrentProcess()->HasSwitch( | |
29 switches::kPluginsMetadataServerURL); | |
30 } | |
31 | |
32 GURL GetPluginsServerURL() { | |
33 std::string filename; | |
34 #if defined(OS_WIN) | |
35 filename = "plugins_win.json"; | |
36 #elif defined(OS_LINUX) | |
37 filename = "plugins_linux.json"; | |
38 #elif defined(OS_MACOSX) | |
39 filename = "plugins_mac.json"; | |
40 #else | |
41 NOTREACHED(); | |
42 #endif | |
43 | |
44 std::string test_url = | |
45 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
46 switches::kPluginsMetadataServerURL); | |
47 return GURL(IsTest() ? test_url : kPluginsServerUrl + filename); | |
48 } | |
49 | |
50 int GetCacheUpdateDelay() { | |
51 return IsTest() ? kTestCacheUpdateDelayMs : kCacheUpdateDelayMs; | |
52 } | |
53 | |
54 } // namespace | |
55 | |
56 PluginsResourceService::PluginsResourceService(PrefService* local_state) | |
57 : WebResourceService(local_state, | |
58 GetPluginsServerURL(), | |
59 false, | |
60 prefs::kPluginsResourceCacheUpdate, | |
61 kStartResourceFetchDelayMs, | |
62 GetCacheUpdateDelay()) { | |
63 } | |
64 | |
65 PluginsResourceService::~PluginsResourceService() { | |
66 } | |
67 | |
68 // static | |
69 void PluginsResourceService::RegisterPrefs(PrefRegistrySimple* registry) { | |
70 registry->RegisterDictionaryPref(prefs::kPluginsMetadata, | |
71 new base::DictionaryValue()); | |
72 registry->RegisterStringPref(prefs::kPluginsResourceCacheUpdate, "0"); | |
73 } | |
74 | |
75 void PluginsResourceService::Unpack(const DictionaryValue& parsed_json) { | |
76 prefs_->Set(prefs::kPluginsMetadata, parsed_json); | |
77 PluginFinder::GetInstance()->ReinitializePlugins(parsed_json); | |
78 } | |
OLD | NEW |