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

Side by Side Diff: chrome/browser/supervised_user/legacy/permission_request_creator_sync.cc

Issue 971733003: Supervised users: When an extension requires new permissions, send request to custodian (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@test_ext_install_disable
Patch Set: test Created 5 years, 9 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
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 "chrome/browser/supervised_user/legacy/permission_request_creator_sync. h" 5 #include "chrome/browser/supervised_user/legacy/permission_request_creator_sync. h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/supervised_user/legacy/supervised_user_shared_settings_ service.h" 9 #include "chrome/browser/supervised_user/legacy/supervised_user_shared_settings_ service.h"
10 #include "chrome/browser/supervised_user/supervised_user_settings_service.h" 10 #include "chrome/browser/supervised_user/supervised_user_settings_service.h"
11 #include "chrome/browser/sync/profile_sync_service.h" 11 #include "chrome/browser/sync/profile_sync_service.h"
12 #include "google_apis/gaia/google_service_auth_error.h" 12 #include "google_apis/gaia/google_service_auth_error.h"
13 #include "net/base/escape.h" 13 #include "net/base/escape.h"
14 #include "url/gurl.h" 14 #include "url/gurl.h"
15 15
16 using base::Time;
17
18 const char kSupervisedUserAccessRequestKeyPrefix[] = 16 const char kSupervisedUserAccessRequestKeyPrefix[] =
19 "X-ManagedUser-AccessRequests"; 17 "X-ManagedUser-AccessRequests";
18 const char kSupervisedUserUpdateRequestKeyPrefix[] =
19 "X-ManagedUser-UpdateRequests";
20 const char kSupervisedUserAccessRequestTime[] = "timestamp"; 20 const char kSupervisedUserAccessRequestTime[] = "timestamp";
21 const char kSupervisedUserName[] = "name"; 21 const char kSupervisedUserName[] = "name";
22 22
23 // Key for the notification setting of the custodian. This is a shared setting 23 // Key for the notification setting of the custodian. This is a shared setting
24 // so we can include the setting in the access request data that is used to 24 // so we can include the setting in the access request data that is used to
25 // trigger notifications. 25 // trigger notifications.
26 const char kNotificationSetting[] = "custodian-notification-setting"; 26 const char kNotificationSetting[] = "custodian-notification-setting";
27 27
28 PermissionRequestCreatorSync::PermissionRequestCreatorSync( 28 PermissionRequestCreatorSync::PermissionRequestCreatorSync(
29 SupervisedUserSettingsService* settings_service, 29 SupervisedUserSettingsService* settings_service,
(...skipping 11 matching lines...) Expand all
41 PermissionRequestCreatorSync::~PermissionRequestCreatorSync() {} 41 PermissionRequestCreatorSync::~PermissionRequestCreatorSync() {}
42 42
43 bool PermissionRequestCreatorSync::IsEnabled() const { 43 bool PermissionRequestCreatorSync::IsEnabled() const {
44 GoogleServiceAuthError::State state = sync_service_->GetAuthError().state(); 44 GoogleServiceAuthError::State state = sync_service_->GetAuthError().state();
45 // We allow requesting access if Sync is working or has a transient error. 45 // We allow requesting access if Sync is working or has a transient error.
46 return (state == GoogleServiceAuthError::NONE || 46 return (state == GoogleServiceAuthError::NONE ||
47 state == GoogleServiceAuthError::CONNECTION_FAILED || 47 state == GoogleServiceAuthError::CONNECTION_FAILED ||
48 state == GoogleServiceAuthError::SERVICE_UNAVAILABLE); 48 state == GoogleServiceAuthError::SERVICE_UNAVAILABLE);
49 } 49 }
50 50
51 void PermissionRequestCreatorSync::CreatePermissionRequest( 51 void PermissionRequestCreatorSync::CreateURLAccessRequest(
52 const GURL& url_requested, 52 const GURL& url_requested,
53 const SuccessCallback& callback) { 53 const SuccessCallback& callback) {
54 // Escape the URL and add the prefix. 54 CreateRequest(kSupervisedUserAccessRequestKeyPrefix,
55 url_requested.spec(),
56 callback);
57 }
58
59 void PermissionRequestCreatorSync::CreateExtensionUpdateRequest(
60 const std::string& extension_id,
61 const SuccessCallback& callback) {
62 CreateRequest(kSupervisedUserUpdateRequestKeyPrefix, extension_id, callback);
63 }
64
65 void PermissionRequestCreatorSync::CreateRequest(
66 const std::string& prefix,
67 const std::string& data,
68 const SuccessCallback& callback) {
69 // Escape the data string and add the prefix.
55 std::string key = SupervisedUserSettingsService::MakeSplitSettingKey( 70 std::string key = SupervisedUserSettingsService::MakeSplitSettingKey(
56 kSupervisedUserAccessRequestKeyPrefix, 71 prefix,
57 net::EscapeQueryParamValue(url_requested.spec(), true)); 72 net::EscapeQueryParamValue(data, true));
58 73
59 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); 74 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
60
61 // TODO(sergiu): Use sane time here when it's ready. 75 // TODO(sergiu): Use sane time here when it's ready.
62 dict->SetDouble(kSupervisedUserAccessRequestTime, 76 dict->SetDouble(kSupervisedUserAccessRequestTime,
63 base::Time::Now().ToJsTime()); 77 base::Time::Now().ToJsTime());
64
65 dict->SetString(kSupervisedUserName, name_); 78 dict->SetString(kSupervisedUserName, name_);
66 79
67 // Copy the notification setting of the custodian. 80 // Copy the notification setting of the custodian.
68 const base::Value* value = shared_settings_service_->GetValue( 81 const base::Value* value = shared_settings_service_->GetValue(
69 supervised_user_id_, kNotificationSetting); 82 supervised_user_id_, kNotificationSetting);
70 bool notifications_enabled = false; 83 bool notifications_enabled = false;
71 if (value) { 84 if (value) {
72 bool success = value->GetAsBoolean(&notifications_enabled); 85 bool success = value->GetAsBoolean(&notifications_enabled);
73 DCHECK(success); 86 DCHECK(success);
74 } 87 }
75 dict->SetBoolean(kNotificationSetting, notifications_enabled); 88 dict->SetBoolean(kNotificationSetting, notifications_enabled);
76 89
77 settings_service_->UploadItem(key, dict.Pass()); 90 settings_service_->UploadItem(key, dict.Pass());
78 91
79 callback.Run(true); 92 callback.Run(true);
80 } 93 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698