1 // Copyright 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.
5 #include "chrome/browser/plugins/plugins_resource_service.h"
7 #include "base/command_line.h"
8 #include "base/prefs/pref_registry_simple.h"
9 #include "base/prefs/pref_service.h"
10 #include "chrome/browser/plugins/plugin_finder.h"
11 #include "chrome/common/chrome_switches.h"
12 #include "chrome/common/pref_names.h"
17 // Delay on first fetch so we don't interfere with startup.
18 const int kStartResourceFetchDelayMs
= 60 * 1000;
20 // Delay between calls to update the cache 1 day and 2 minutes in testing mode.
21 const int kCacheUpdateDelayMs
= 24 * 60 * 60 * 1000;
23 const char kPluginsServerUrl
[] =
24 "https://www.gstatic.com/chrome/config/plugins_2/";
26 GURL
GetPluginsServerURL() {
29 filename
= "plugins_win.json";
30 #elif defined(OS_LINUX)
31 filename
= "plugins_linux.json";
32 #elif defined(OS_MACOSX)
33 filename
= "plugins_mac.json";
35 #error Unknown platform
38 return GURL(kPluginsServerUrl
+ filename
);
43 PluginsResourceService::PluginsResourceService(PrefService
* local_state
)
44 : ChromeWebResourceService(local_state
,
45 GetPluginsServerURL(),
47 prefs::kPluginsResourceCacheUpdate
,
48 kStartResourceFetchDelayMs
,
49 kCacheUpdateDelayMs
) {
52 void PluginsResourceService::Init() {
53 const base::DictionaryValue
* metadata
=
54 prefs_
->GetDictionary(prefs::kPluginsMetadata
);
55 PluginFinder::GetInstance()->ReinitializePlugins(metadata
);
59 PluginsResourceService::~PluginsResourceService() {
63 void PluginsResourceService::RegisterPrefs(PrefRegistrySimple
* registry
) {
64 registry
->RegisterDictionaryPref(prefs::kPluginsMetadata
,
65 new base::DictionaryValue());
66 registry
->RegisterStringPref(prefs::kPluginsResourceCacheUpdate
, "0");
69 void PluginsResourceService::Unpack(const base::DictionaryValue
& parsed_json
) {
70 prefs_
->Set(prefs::kPluginsMetadata
, parsed_json
);
71 PluginFinder::GetInstance()->ReinitializePlugins(&parsed_json
);