OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/suggestions/suggestions_service.h" | 5 #include "components/suggestions/suggestions_service.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
| 9 #include "base/location.h" |
9 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop_proxy.h" | |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "base/metrics/sparse_histogram.h" | 12 #include "base/metrics/sparse_histogram.h" |
| 13 #include "base/single_thread_task_runner.h" |
13 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/thread_task_runner_handle.h" |
15 #include "base/time/time.h" | 17 #include "base/time/time.h" |
16 #include "components/pref_registry/pref_registry_syncable.h" | 18 #include "components/pref_registry/pref_registry_syncable.h" |
17 #include "components/suggestions/blacklist_store.h" | 19 #include "components/suggestions/blacklist_store.h" |
18 #include "components/suggestions/suggestions_store.h" | 20 #include "components/suggestions/suggestions_store.h" |
19 #include "components/variations/net/variations_http_header_provider.h" | 21 #include "components/variations/net/variations_http_header_provider.h" |
20 #include "net/base/escape.h" | 22 #include "net/base/escape.h" |
21 #include "net/base/load_flags.h" | 23 #include "net/base/load_flags.h" |
22 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" |
23 #include "net/base/url_util.h" | 25 #include "net/base/url_util.h" |
24 #include "net/http/http_response_headers.h" | 26 #include "net/http/http_response_headers.h" |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 } | 325 } |
324 | 326 |
325 void SuggestionsService::ScheduleBlacklistUpload() { | 327 void SuggestionsService::ScheduleBlacklistUpload() { |
326 DCHECK(thread_checker_.CalledOnValidThread()); | 328 DCHECK(thread_checker_.CalledOnValidThread()); |
327 TimeDelta time_delta; | 329 TimeDelta time_delta; |
328 if (blacklist_store_->GetTimeUntilReadyForUpload(&time_delta)) { | 330 if (blacklist_store_->GetTimeUntilReadyForUpload(&time_delta)) { |
329 // Blacklist cache is not empty: schedule. | 331 // Blacklist cache is not empty: schedule. |
330 base::Closure blacklist_cb = | 332 base::Closure blacklist_cb = |
331 base::Bind(&SuggestionsService::UploadOneFromBlacklist, | 333 base::Bind(&SuggestionsService::UploadOneFromBlacklist, |
332 weak_ptr_factory_.GetWeakPtr()); | 334 weak_ptr_factory_.GetWeakPtr()); |
333 base::MessageLoopProxy::current()->PostDelayedTask( | 335 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
334 FROM_HERE, blacklist_cb, time_delta + scheduling_delay_); | 336 FROM_HERE, blacklist_cb, time_delta + scheduling_delay_); |
335 } | 337 } |
336 } | 338 } |
337 | 339 |
338 void SuggestionsService::UploadOneFromBlacklist() { | 340 void SuggestionsService::UploadOneFromBlacklist() { |
339 DCHECK(thread_checker_.CalledOnValidThread()); | 341 DCHECK(thread_checker_.CalledOnValidThread()); |
340 | 342 |
341 GURL blacklist_url; | 343 GURL blacklist_url; |
342 if (blacklist_store_->GetCandidateForUpload(&blacklist_url)) { | 344 if (blacklist_store_->GetCandidateForUpload(&blacklist_url)) { |
343 // Issue a blacklisting request. Even if this request ends up not being sent | 345 // Issue a blacklisting request. Even if this request ends up not being sent |
(...skipping 15 matching lines...) Expand all Loading... |
359 scheduling_delay_ = TimeDelta::FromSeconds(kDefaultSchedulingDelaySec); | 361 scheduling_delay_ = TimeDelta::FromSeconds(kDefaultSchedulingDelaySec); |
360 } else { | 362 } else { |
361 TimeDelta candidate_delay = | 363 TimeDelta candidate_delay = |
362 scheduling_delay_ * kSchedulingBackoffMultiplier; | 364 scheduling_delay_ * kSchedulingBackoffMultiplier; |
363 if (candidate_delay < TimeDelta::FromSeconds(kSchedulingMaxDelaySec)) | 365 if (candidate_delay < TimeDelta::FromSeconds(kSchedulingMaxDelaySec)) |
364 scheduling_delay_ = candidate_delay; | 366 scheduling_delay_ = candidate_delay; |
365 } | 367 } |
366 } | 368 } |
367 | 369 |
368 } // namespace suggestions | 370 } // namespace suggestions |
OLD | NEW |