Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: chrome/browser/net/prediction_helper.cc

Issue 357723003: Implement prediction_options. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix typo. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/net/prediction_helper.h"
6
7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/net/predictor.h"
9 #include "chrome/browser/profiles/profile_io_data.h"
10 #include "chrome/common/pref_names.h"
11 #include "components/pref_registry/pref_registry_syncable.h"
12 #include "net/base/network_change_notifier.h"
13
14 namespace {
15
16 bool CanPredictNetworkActions(int AllowNetworkPrediction,
17 bool NetworkPredictionEnabled) {
18 switch (AllowNetworkPrediction) {
19 case chrome_browser_net::Predictor::NETWORK_PREDICTION_ALWAYS:
20 return true;
21 case chrome_browser_net::Predictor::NETWORK_PREDICTION_WIFI_ONLY:
22 return !net::NetworkChangeNotifier::IsConnectionCellular(
23 net::NetworkChangeNotifier::GetConnectionType());
mmenke 2014/06/26 20:41:01 nit: Suggest just using a 4-space indent here.
Bence 2014/06/27 15:11:50 Done.
24 case chrome_browser_net::Predictor::NETWORK_PREDICTION_NEVER:
25 return false;
26 case chrome_browser_net::Predictor::NETWORK_PREDICTION_UNSET:
27 return NetworkPredictionEnabled;
28 default:
29 NOTREACHED() << "Unknown kAllowNetworkPrediction value.";
mmenke 2014/06/26 20:41:01 Include base/logging.h for NOTREACHED and DCHECK.
Bence 2014/06/27 15:11:50 Done.
30 return false;
31 }
32 }
33
34 } // anonymous namespace
mmenke 2014/06/26 20:41:01 nit: --anonymous
Bence 2014/06/27 15:11:50 Done.
35
36 namespace chrome_browser_net {
37
38 void RegisterPredictionHelperProfilePrefs(
39 user_prefs::PrefRegistrySyncable* registry) {
40 registry->RegisterIntegerPref(
41 prefs::kAllowNetworkPrediction,
42 chrome_browser_net::Predictor::NETWORK_PREDICTION_UNSET,
43 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
44 }
45
46 // To be executed on the IO thread only.
mmenke 2014/06/26 20:41:01 Function level comments should generally be with t
Bence 2014/06/27 15:11:50 Done.
47 bool CanPredictNetworkActionsIO(content::ResourceContext* resource_context) {
48 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
49 DCHECK(resource_context);
mmenke 2014/06/26 20:41:01 nit: Generally, there's a blank line between DCHE
Bence 2014/06/27 15:11:50 Done.
50 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
51 if (io_data == NULL)
mmenke 2014/06/26 20:41:01 Can this ever be NULL? Looks like other consumers
Bence 2014/06/27 15:11:50 Done.
52 return false;
53 return CanPredictNetworkActions(
54 io_data->allow_network_prediction()->GetValue(),
55 io_data->network_prediction_enabled()->GetValue());
56 }
57
58 // To be executed on the UI thread only.
mmenke 2014/06/26 20:41:01 nit: Remove comment.
Bence 2014/06/27 15:11:50 Done.
59 bool CanPredictNetworkActionsUI(PrefService* prefs) {
60 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
61 DCHECK(prefs);
62 return CanPredictNetworkActions(
63 prefs->GetInteger(prefs::kAllowNetworkPrediction),
64 prefs->GetBoolean(prefs::kNetworkPredictionEnabled));
65 }
66
67 } // namespace chrome_browser_net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698