| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 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/bind.h" |
| 7 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 8 #include "base/prefs/pref_registry_simple.h" | 9 #include "base/prefs/pref_registry_simple.h" |
| 9 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| 11 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/plugins/plugin_finder.h" | 12 #include "chrome/browser/plugins/plugin_finder.h" |
| 11 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
| 12 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
| 15 #include "components/safe_json/safe_json_parser.h" |
| 13 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 14 | 17 |
| 15 namespace { | 18 namespace { |
| 16 | 19 |
| 17 // Delay on first fetch so we don't interfere with startup. | 20 // Delay on first fetch so we don't interfere with startup. |
| 18 const int kStartResourceFetchDelayMs = 60 * 1000; | 21 const int kStartResourceFetchDelayMs = 60 * 1000; |
| 19 | 22 |
| 20 // Delay between calls to update the cache 1 day and 2 minutes in testing mode. | 23 // Delay between calls to update the cache 1 day and 2 minutes in testing mode. |
| 21 const int kCacheUpdateDelayMs = 24 * 60 * 60 * 1000; | 24 const int kCacheUpdateDelayMs = 24 * 60 * 60 * 1000; |
| 22 | 25 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 34 #else | 37 #else |
| 35 #error Unknown platform | 38 #error Unknown platform |
| 36 #endif | 39 #endif |
| 37 | 40 |
| 38 return GURL(kPluginsServerUrl + filename); | 41 return GURL(kPluginsServerUrl + filename); |
| 39 } | 42 } |
| 40 | 43 |
| 41 } // namespace | 44 } // namespace |
| 42 | 45 |
| 43 PluginsResourceService::PluginsResourceService(PrefService* local_state) | 46 PluginsResourceService::PluginsResourceService(PrefService* local_state) |
| 44 : ChromeWebResourceService(local_state, | 47 : web_resource::WebResourceService( |
| 45 GetPluginsServerURL(), | 48 local_state, |
| 46 false, | 49 GetPluginsServerURL(), |
| 47 prefs::kPluginsResourceCacheUpdate, | 50 std::string(), |
| 48 kStartResourceFetchDelayMs, | 51 prefs::kPluginsResourceCacheUpdate, |
| 49 kCacheUpdateDelayMs) { | 52 kStartResourceFetchDelayMs, |
| 50 } | 53 kCacheUpdateDelayMs, |
| 54 g_browser_process->system_request_context(), |
| 55 switches::kDisableBackgroundNetworking, |
| 56 base::Bind(safe_json::SafeJsonParser::Parse)) {} |
| 51 | 57 |
| 52 void PluginsResourceService::Init() { | 58 void PluginsResourceService::Init() { |
| 53 const base::DictionaryValue* metadata = | 59 const base::DictionaryValue* metadata = |
| 54 prefs_->GetDictionary(prefs::kPluginsMetadata); | 60 prefs_->GetDictionary(prefs::kPluginsMetadata); |
| 55 PluginFinder::GetInstance()->ReinitializePlugins(metadata); | 61 PluginFinder::GetInstance()->ReinitializePlugins(metadata); |
| 56 StartAfterDelay(); | 62 StartAfterDelay(); |
| 57 } | 63 } |
| 58 | 64 |
| 59 PluginsResourceService::~PluginsResourceService() { | 65 PluginsResourceService::~PluginsResourceService() { |
| 60 } | 66 } |
| 61 | 67 |
| 62 // static | 68 // static |
| 63 void PluginsResourceService::RegisterPrefs(PrefRegistrySimple* registry) { | 69 void PluginsResourceService::RegisterPrefs(PrefRegistrySimple* registry) { |
| 64 registry->RegisterDictionaryPref(prefs::kPluginsMetadata, | 70 registry->RegisterDictionaryPref(prefs::kPluginsMetadata, |
| 65 new base::DictionaryValue()); | 71 new base::DictionaryValue()); |
| 66 registry->RegisterStringPref(prefs::kPluginsResourceCacheUpdate, "0"); | 72 registry->RegisterStringPref(prefs::kPluginsResourceCacheUpdate, "0"); |
| 67 } | 73 } |
| 68 | 74 |
| 69 void PluginsResourceService::Unpack(const base::DictionaryValue& parsed_json) { | 75 void PluginsResourceService::Unpack(const base::DictionaryValue& parsed_json) { |
| 70 prefs_->Set(prefs::kPluginsMetadata, parsed_json); | 76 prefs_->Set(prefs::kPluginsMetadata, parsed_json); |
| 71 PluginFinder::GetInstance()->ReinitializePlugins(&parsed_json); | 77 PluginFinder::GetInstance()->ReinitializePlugins(&parsed_json); |
| 72 } | 78 } |
| OLD | NEW |