| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/google_url_tracker.h" | 5 #include "chrome/browser/google_url_tracker.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/profile.h" | 10 #include "chrome/browser/profile.h" |
| 11 #include "chrome/common/notification_service.h" | 11 #include "chrome/common/notification_service.h" |
| 12 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
| 13 #include "chrome/common/pref_service.h" | 13 #include "chrome/common/pref_service.h" |
| 14 #include "net/base/load_flags.h" | 14 #include "net/base/load_flags.h" |
| 15 #include "net/url_request/url_request_status.h" | 15 #include "net/url_request/url_request_status.h" |
| 16 | 16 |
| 17 const char GoogleURLTracker::kDefaultGoogleHomepage[] = | 17 const char GoogleURLTracker::kDefaultGoogleHomepage[] = |
| 18 "http://www.google.com/"; | 18 "http://www.google.com/"; |
| 19 | 19 |
| 20 GoogleURLTracker::GoogleURLTracker() | 20 GoogleURLTracker::GoogleURLTracker() |
| 21 : google_url_(WideToUTF8(g_browser_process->local_state()->GetString( | 21 : google_url_(WideToUTF8(g_browser_process->local_state()->GetString( |
| 22 prefs::kLastKnownGoogleURL))), | 22 prefs::kLastKnownGoogleURL))), |
| 23 ALLOW_THIS_IN_INITIALIZER_LIST(fetcher_factory_(this)), | 23 ALLOW_THIS_IN_INITIALIZER_LIST(fetcher_factory_(this)), |
| 24 in_startup_sleep_(true), | 24 in_startup_sleep_(true), |
| 25 already_fetched_(false), | 25 already_fetched_(false), |
| 26 need_to_fetch_(false), | 26 need_to_fetch_(false), |
| 27 request_context_available_(!!Profile::GetDefaultRequestContext()) { | 27 request_context_available_(!!Profile::GetDefaultRequestContext()) { |
| 28 NotificationService::current()->AddObserver(this, | 28 registrar_.Add(this, NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE, |
| 29 NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE, | 29 NotificationService::AllSources()); |
| 30 NotificationService::AllSources()); | |
| 31 | 30 |
| 32 // Because this function can be called during startup, when kicking off a URL | 31 // Because this function can be called during startup, when kicking off a URL |
| 33 // fetch can eat up 20 ms of time, we delay five seconds, which is hopefully | 32 // fetch can eat up 20 ms of time, we delay five seconds, which is hopefully |
| 34 // long enough to be after startup, but still get results back quickly. | 33 // long enough to be after startup, but still get results back quickly. |
| 35 // Ideally, instead of this timer, we'd do something like "check if the | 34 // Ideally, instead of this timer, we'd do something like "check if the |
| 36 // browser is starting up, and if so, come back later", but there is currently | 35 // browser is starting up, and if so, come back later", but there is currently |
| 37 // no function to do this. | 36 // no function to do this. |
| 38 static const int kStartFetchDelayMS = 5000; | 37 static const int kStartFetchDelayMS = 5000; |
| 39 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 38 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 40 fetcher_factory_.NewRunnableMethod(&GoogleURLTracker::FinishSleep), | 39 fetcher_factory_.NewRunnableMethod(&GoogleURLTracker::FinishSleep), |
| 41 kStartFetchDelayMS); | 40 kStartFetchDelayMS); |
| 42 } | 41 } |
| 43 | 42 |
| 44 GoogleURLTracker::~GoogleURLTracker() { | 43 GoogleURLTracker::~GoogleURLTracker() { |
| 45 NotificationService::current()->RemoveObserver(this, | |
| 46 NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE, | |
| 47 NotificationService::AllSources()); | |
| 48 } | 44 } |
| 49 | 45 |
| 50 // static | 46 // static |
| 51 GURL GoogleURLTracker::GoogleURL() { | 47 GURL GoogleURLTracker::GoogleURL() { |
| 52 const GoogleURLTracker* const tracker = | 48 const GoogleURLTracker* const tracker = |
| 53 g_browser_process->google_url_tracker(); | 49 g_browser_process->google_url_tracker(); |
| 54 return tracker ? tracker->google_url_ : GURL(kDefaultGoogleHomepage); | 50 return tracker ? tracker->google_url_ : GURL(kDefaultGoogleHomepage); |
| 55 } | 51 } |
| 56 | 52 |
| 57 // static | 53 // static |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 } | 159 } |
| 164 } | 160 } |
| 165 | 161 |
| 166 void GoogleURLTracker::Observe(NotificationType type, | 162 void GoogleURLTracker::Observe(NotificationType type, |
| 167 const NotificationSource& source, | 163 const NotificationSource& source, |
| 168 const NotificationDetails& details) { | 164 const NotificationDetails& details) { |
| 169 DCHECK_EQ(NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE, type.value); | 165 DCHECK_EQ(NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE, type.value); |
| 170 request_context_available_ = true; | 166 request_context_available_ = true; |
| 171 StartFetchIfDesirable(); | 167 StartFetchIfDesirable(); |
| 172 } | 168 } |
| OLD | NEW |