diff options
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/browser.vcproj | 8 | ||||
-rw-r--r-- | chrome/browser/browser_main.cc | 11 | ||||
-rw-r--r-- | chrome/browser/net/sdch_dictionary_fetcher.cc | 45 | ||||
-rw-r--r-- | chrome/browser/net/sdch_dictionary_fetcher.h | 66 |
4 files changed, 130 insertions, 0 deletions
diff --git a/chrome/browser/browser.vcproj b/chrome/browser/browser.vcproj index fc3c31b..e87a3e0 100644 --- a/chrome/browser/browser.vcproj +++ b/chrome/browser/browser.vcproj @@ -1861,6 +1861,14 @@ RelativePath=".\net\dns_slave.h" > </File> + <File + RelativePath=".\net\sdch_dictionary_fetcher.cc" + > + </File> + <File + RelativePath=".\net\sdch_dictionary_fetcher.h" + > + </File> </Filter> <Filter Name="RLZ" diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index 15703a2..fbb216a9 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -30,6 +30,7 @@ #include "chrome/browser/jankometer.h" #include "chrome/browser/metrics_service.h" #include "chrome/browser/net/dns_global.h" +#include "chrome/browser/net/sdch_dictionary_fetcher.h" #include "chrome/browser/plugin_service.h" #include "chrome/browser/printing/print_job_manager.h" #include "chrome/browser/rlz/rlz.h" @@ -53,6 +54,7 @@ #include "net/base/net_module.h" #include "net/base/net_resources.h" #include "net/base/net_util.h" +#include "net/base/sdch_manager.h" #include "net/base/winsock_init.h" #include "net/http/http_network_layer.h" @@ -475,6 +477,15 @@ int BrowserMain(CommandLine &parsed_command_line, int show_command, // Initialize the CertStore. CertStore::Initialize(); + // Prepare for memory caching of SDCH dictionaries. + SdchManager sdch_manager; // Construct singleton database. + if (parsed_command_line.HasSwitch(switches::kSdchFilter)) { + sdch_manager.set_sdch_fetcher(new SdchDictionaryFetcher); + std::wstring switch_domain = + parsed_command_line.GetSwitchValue(switches::kSdchFilter); + sdch_manager.enable_sdch_support(WideToASCII(switch_domain)); + } + MetricsService* metrics = NULL; if (!parsed_command_line.HasSwitch(switches::kDisableMetrics)) { if (parsed_command_line.HasSwitch(switches::kDisableMetricsReporting)) { diff --git a/chrome/browser/net/sdch_dictionary_fetcher.cc b/chrome/browser/net/sdch_dictionary_fetcher.cc new file mode 100644 index 0000000..1b5c21c --- /dev/null +++ b/chrome/browser/net/sdch_dictionary_fetcher.cc @@ -0,0 +1,45 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/net/sdch_dictionary_fetcher.h" +#include "chrome/browser/profile.h" + +void SdchDictionaryFetcher::Schedule(const GURL& dictionary_url) { + fetch_queue_.push(dictionary_url); + ScheduleDelayedRun(); +} + +// TODO(jar): If QOS low priority is supported, switch to using that instead of +// just waiting to do the fetch. +void SdchDictionaryFetcher::ScheduleDelayedRun() { + if (fetch_queue_.empty() || current_fetch_.get() || task_is_pending_) + return; + MessageLoop::current()->PostDelayedTask(FROM_HERE, + method_factory_.NewRunnableMethod(&SdchDictionaryFetcher::StartFetching), + kMsDelayFromRequestTillDownload); + task_is_pending_ = true; +} + +void SdchDictionaryFetcher::StartFetching() { + DCHECK(task_is_pending_); + task_is_pending_ = false; + + current_fetch_.reset(new URLFetcher(fetch_queue_.front(), URLFetcher::GET, + this)); + fetch_queue_.pop(); + current_fetch_->set_request_context(Profile::GetDefaultRequestContext()); + current_fetch_->Start(); +} + +void SdchDictionaryFetcher::OnURLFetchComplete(const URLFetcher* source, + const GURL& url, + const URLRequestStatus& status, + int response_code, + const ResponseCookies& cookies, + const std::string& data) { + if (200 == response_code) + SdchManager::Global()->AddSdchDictionary(data, url); + current_fetch_.reset(NULL); + ScheduleDelayedRun(); +} diff --git a/chrome/browser/net/sdch_dictionary_fetcher.h b/chrome/browser/net/sdch_dictionary_fetcher.h new file mode 100644 index 0000000..34d3f28 --- /dev/null +++ b/chrome/browser/net/sdch_dictionary_fetcher.h @@ -0,0 +1,66 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Support modularity by calling to load a new SDCH filter dictionary. +// Note that this sort of calling can't be done in the /net directory, as it has +// no concept of the HTTP cache (which is only visible at the browser level). + +#ifndef CHROME_BROWSER_NET_SDCH_DICTIONARY_FETCHER_H_ +#define CHROME_BROWSER_NET_SDCH_DICTIONARY_FETCHER_H_ + +#include <queue> +#include <string> + +#include "base/task.h" +#include "chrome/browser/url_fetcher.h" +#include "net/base/sdch_manager.h" + +class SdchDictionaryFetcher : public URLFetcher::Delegate, + public SdchFetcher { + public: + #pragma warning(suppress: 4355) // OK to pass "this" here. + SdchDictionaryFetcher() : method_factory_(this), task_is_pending_(false) {} + virtual ~SdchDictionaryFetcher() {} + + // Implementation of SdchFetcher class. + // This method gets the requested dictionary, and then calls back into the + // SdchManager class with the dictionary's text. + virtual void Schedule(const GURL& dictionary_url); + + private: + // Delay between Schedule and actual download. + static const int kMsDelayFromRequestTillDownload = 15000; + + // Ensure the download after the above delay. + void ScheduleDelayedRun(); + + // Make sure we're processing (or waiting for) the the arrival of the next URL + // in the |fetch_queue_|. + void StartFetching(); + + // Implementation of URLFetcher::Delegate. Called after transmission + // completes (either successfully or with failure). + virtual void OnURLFetchComplete(const URLFetcher* source, + const GURL& url, + const URLRequestStatus& status, + int response_code, + const ResponseCookies& cookies, + const std::string& data); + + // A queue of URLs that are being used to download dictionaries. + std::queue<GURL> fetch_queue_; + // The currently outstanding URL fetch of a dicitonary. + // If this is null, then there is no outstanding request. + scoped_ptr<URLFetcher> current_fetch_; + + // Always spread out the dictionary fetches, so that they don't steal + // bandwidth from the actual page load. Create delayed tasks to spread out + // the download. + ScopedRunnableMethodFactory<SdchDictionaryFetcher> method_factory_; + bool task_is_pending_; + + DISALLOW_COPY_AND_ASSIGN(SdchDictionaryFetcher); +}; + +#endif // CHROME_BROWSER_NET_SDCH_DICTIONARY_FETCHER_H_ |