This source file includes following definitions.
- IsTest
- GetPluginsServerURL
- GetCacheUpdateDelay
- Init
- RegisterPrefs
- Unpack
#include "chrome/browser/plugins/plugins_resource_service.h"
#include "base/command_line.h"
#include "base/prefs/pref_registry_simple.h"
#include "base/prefs/pref_service.h"
#include "chrome/browser/plugins/plugin_finder.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "url/gurl.h"
namespace {
const int kStartResourceFetchDelayMs = 60 * 1000;
const int kCacheUpdateDelayMs = 24 * 60 * 60 * 1000;
const int kTestCacheUpdateDelayMs = 2 * 60 * 1000;
const char kPluginsServerUrl[] =
"https://www.gstatic.com/chrome/config/plugins_2/";
bool IsTest() {
return CommandLine::ForCurrentProcess()->HasSwitch(
switches::kPluginsMetadataServerURL);
}
GURL GetPluginsServerURL() {
std::string filename;
#if defined(OS_WIN)
filename = "plugins_win.json";
#elif defined(OS_LINUX)
filename = "plugins_linux.json";
#elif defined(OS_MACOSX)
filename = "plugins_mac.json";
#else
#error Unknown platform
#endif
std::string test_url =
CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kPluginsMetadataServerURL);
return GURL(IsTest() ? test_url : kPluginsServerUrl + filename);
}
int GetCacheUpdateDelay() {
return IsTest() ? kTestCacheUpdateDelayMs : kCacheUpdateDelayMs;
}
}
PluginsResourceService::PluginsResourceService(PrefService* local_state)
: WebResourceService(local_state,
GetPluginsServerURL(),
false,
prefs::kPluginsResourceCacheUpdate,
kStartResourceFetchDelayMs,
GetCacheUpdateDelay()) {
}
void PluginsResourceService::Init() {
const base::DictionaryValue* metadata =
prefs_->GetDictionary(prefs::kPluginsMetadata);
PluginFinder::GetInstance()->ReinitializePlugins(metadata);
StartAfterDelay();
}
PluginsResourceService::~PluginsResourceService() {
}
void PluginsResourceService::RegisterPrefs(PrefRegistrySimple* registry) {
registry->RegisterDictionaryPref(prefs::kPluginsMetadata,
new base::DictionaryValue());
registry->RegisterStringPref(prefs::kPluginsResourceCacheUpdate, "0");
}
void PluginsResourceService::Unpack(const base::DictionaryValue& parsed_json) {
prefs_->Set(prefs::kPluginsMetadata, parsed_json);
PluginFinder::GetInstance()->ReinitializePlugins(&parsed_json);
}