| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "cloud_print/service/win/chrome_launcher.h" | 5 #include "cloud_print/service/win/chrome_launcher.h" |
| 6 | 6 |
| 7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 } | 78 } |
| 79 | 79 |
| 80 GURL GetCloudPrintServiceEnableURLWithSignin(const std::string& proxy_id) { | 80 GURL GetCloudPrintServiceEnableURLWithSignin(const std::string& proxy_id) { |
| 81 GURL url(GaiaUrls::GetInstance()->service_login_url()); | 81 GURL url(GaiaUrls::GetInstance()->service_login_url()); |
| 82 url = net::AppendQueryParameter(url, "service", "cloudprint"); | 82 url = net::AppendQueryParameter(url, "service", "cloudprint"); |
| 83 url = net::AppendQueryParameter(url, "sarp", "1"); | 83 url = net::AppendQueryParameter(url, "sarp", "1"); |
| 84 return net::AppendQueryParameter( | 84 return net::AppendQueryParameter( |
| 85 url, "continue", GetCloudPrintServiceEnableURL(proxy_id).spec()); | 85 url, "continue", GetCloudPrintServiceEnableURL(proxy_id).spec()); |
| 86 } | 86 } |
| 87 | 87 |
| 88 std::string UpdateServiceState(const std::string& json) { | 88 std::string UpdateServiceState(const std::string& json, |
| 89 const std::string& proxy_id) { |
| 89 std::string result; | 90 std::string result; |
| 90 | 91 |
| 91 scoped_ptr<base::Value> service_state(base::JSONReader::Read(json)); | 92 scoped_ptr<base::Value> service_state(base::JSONReader::Read(json)); |
| 92 base::DictionaryValue* dictionary = NULL; | 93 base::DictionaryValue* dictionary = NULL; |
| 93 if (!service_state->GetAsDictionary(&dictionary) || !dictionary) { | 94 if (!service_state->GetAsDictionary(&dictionary) || !dictionary) { |
| 94 return result; | 95 return result; |
| 95 } | 96 } |
| 96 | 97 |
| 97 bool enabled = false; | 98 bool enabled = false; |
| 98 if (!dictionary->GetBoolean(prefs::kCloudPrintProxyEnabled, &enabled) || | 99 if (!dictionary->GetBoolean(prefs::kCloudPrintProxyEnabled, &enabled) || |
| 99 !enabled) { | 100 !enabled) { |
| 100 return result; | 101 return result; |
| 101 } | 102 } |
| 102 | 103 |
| 103 // Remove everything except kCloudPrintRoot. | 104 // Remove everything except kCloudPrintRoot. |
| 104 base::Value* cloud_print_root = NULL; | 105 base::Value* cloud_print_root = NULL; |
| 105 dictionary->Remove(prefs::kCloudPrintRoot, &cloud_print_root); | 106 dictionary->Remove(prefs::kCloudPrintRoot, &cloud_print_root); |
| 106 dictionary->Clear(); | 107 dictionary->Clear(); |
| 107 dictionary->Set(prefs::kCloudPrintRoot, cloud_print_root); | 108 dictionary->Set(prefs::kCloudPrintRoot, cloud_print_root); |
| 108 | 109 |
| 109 dictionary->SetBoolean(prefs::kCloudPrintXmppPingEnabled, true); | 110 dictionary->SetBoolean(prefs::kCloudPrintXmppPingEnabled, true); |
| 110 | 111 dictionary->SetString(prefs::kCloudPrintProxyId, proxy_id); |
| 111 base::JSONWriter::Write(dictionary, &result); | 112 base::JSONWriter::WriteWithOptions(dictionary, |
| 112 | 113 base::JSONWriter::OPTIONS_PRETTY_PRINT, |
| 114 &result); |
| 113 return result; | 115 return result; |
| 114 } | 116 } |
| 115 | 117 |
| 116 void DeleteAutorunKeys(const base::FilePath& user_data_dir) { | 118 void DeleteAutorunKeys(const base::FilePath& user_data_dir) { |
| 117 base::win::RegKey key(HKEY_CURRENT_USER, kAutoRunKeyPath, KEY_SET_VALUE); | 119 base::win::RegKey key(HKEY_CURRENT_USER, kAutoRunKeyPath, KEY_SET_VALUE); |
| 118 if (!key.Valid()) | 120 if (!key.Valid()) |
| 119 return; | 121 return; |
| 120 std::vector<string16> to_delete; | 122 std::vector<string16> to_delete; |
| 121 | 123 |
| 122 base::FilePath abs_user_data_dir = user_data_dir; | 124 base::FilePath abs_user_data_dir = user_data_dir; |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 LOG(ERROR) << "Chrome launch failed."; | 297 LOG(ERROR) << "Chrome launch failed."; |
| 296 return result; | 298 return result; |
| 297 } | 299 } |
| 298 | 300 |
| 299 std::string json; | 301 std::string json; |
| 300 if (!file_util::ReadFileToString( | 302 if (!file_util::ReadFileToString( |
| 301 temp_user_data.path().Append(chrome::kServiceStateFileName), &json)) { | 303 temp_user_data.path().Append(chrome::kServiceStateFileName), &json)) { |
| 302 return result; | 304 return result; |
| 303 } | 305 } |
| 304 | 306 |
| 305 return UpdateServiceState(json); | 307 return UpdateServiceState(json, proxy_id); |
| 306 } | 308 } |
| 307 | 309 |
| OLD | NEW |