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 "chrome/browser/ui/webui/sync_setup_handler.h" | 5 #include "chrome/browser/ui/webui/sync_setup_handler.h" |
6 | 6 |
| 7 #include "base/basictypes.h" |
7 #include "base/bind.h" | 8 #include "base/bind.h" |
8 #include "base/basictypes.h" | |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/json/json_reader.h" | 12 #include "base/json/json_reader.h" |
13 #include "base/json/json_writer.h" | 13 #include "base/json/json_writer.h" |
14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "chrome/app/chrome_command_ids.h" | 16 #include "chrome/app/chrome_command_ids.h" |
17 #include "chrome/browser/google/google_util.h" | 17 #include "chrome/browser/google/google_util.h" |
18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/profiles/profile_info_cache.h" | 19 #include "chrome/browser/profiles/profile_info_cache.h" |
20 #include "chrome/browser/profiles/profile_manager.h" | 20 #include "chrome/browser/profiles/profile_manager.h" |
21 #include "chrome/browser/profiles/profile_metrics.h" | 21 #include "chrome/browser/profiles/profile_metrics.h" |
22 #include "chrome/browser/signin/signin_manager.h" | 22 #include "chrome/browser/signin/signin_manager.h" |
23 #include "chrome/browser/signin/signin_manager_factory.h" | 23 #include "chrome/browser/signin/signin_manager_factory.h" |
24 #include "chrome/browser/sync/profile_sync_service.h" | 24 #include "chrome/browser/sync/profile_sync_service.h" |
25 #include "chrome/browser/sync/profile_sync_service_factory.h" | 25 #include "chrome/browser/sync/profile_sync_service_factory.h" |
26 #include "chrome/browser/ui/browser_list.h" | 26 #include "chrome/browser/ui/browser_list.h" |
27 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | 27 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
28 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 28 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
29 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" | 29 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" |
30 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
| 31 #include "chrome/common/net/gaia/gaia_constants.h" |
31 #include "chrome/common/url_constants.h" | 32 #include "chrome/common/url_constants.h" |
32 #include "chrome/common/net/gaia/gaia_constants.h" | |
33 #include "content/public/browser/render_view_host.h" | 33 #include "content/public/browser/render_view_host.h" |
34 #include "content/public/browser/render_view_host_delegate.h" | 34 #include "content/public/browser/render_view_host_delegate.h" |
35 #include "content/public/browser/web_contents.h" | 35 #include "content/public/browser/web_contents.h" |
36 #include "grit/chromium_strings.h" | 36 #include "grit/chromium_strings.h" |
37 #include "grit/generated_resources.h" | 37 #include "grit/generated_resources.h" |
38 #include "grit/locale_settings.h" | 38 #include "grit/locale_settings.h" |
39 #include "sync/protocol/service_constants.h" | |
40 #include "ui/base/l10n/l10n_util.h" | 39 #include "ui/base/l10n/l10n_util.h" |
41 | 40 |
42 using l10n_util::GetStringFUTF16; | 41 using l10n_util::GetStringFUTF16; |
43 using l10n_util::GetStringUTF16; | 42 using l10n_util::GetStringUTF16; |
44 | 43 |
45 namespace { | 44 namespace { |
46 | 45 |
47 // A structure which contains all the configuration information for sync. | 46 // A structure which contains all the configuration information for sync. |
48 struct SyncConfigInfo { | 47 struct SyncConfigInfo { |
49 SyncConfigInfo(); | 48 SyncConfigInfo(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 syncable::PREFERENCES, | 84 syncable::PREFERENCES, |
86 syncable::SESSIONS, | 85 syncable::SESSIONS, |
87 syncable::THEMES, | 86 syncable::THEMES, |
88 syncable::TYPED_URLS | 87 syncable::TYPED_URLS |
89 }; | 88 }; |
90 | 89 |
91 static const size_t kNumDataTypes = arraysize(kDataTypes); | 90 static const size_t kNumDataTypes = arraysize(kDataTypes); |
92 COMPILE_ASSERT(arraysize(kDataTypeNames) == arraysize(kDataTypes), | 91 COMPILE_ASSERT(arraysize(kDataTypeNames) == arraysize(kDataTypes), |
93 kDataTypes_does_not_match_kDataTypeNames); | 92 kDataTypes_does_not_match_kDataTypeNames); |
94 | 93 |
| 94 static const char kDefaultSigninDomain[] = "gmail.com"; |
| 95 |
95 bool GetAuthData(const std::string& json, | 96 bool GetAuthData(const std::string& json, |
96 std::string* username, | 97 std::string* username, |
97 std::string* password, | 98 std::string* password, |
98 std::string* captcha, | 99 std::string* captcha, |
99 std::string* otp, | 100 std::string* otp, |
100 std::string* access_code) { | 101 std::string* access_code) { |
101 scoped_ptr<Value> parsed_value(base::JSONReader::Read(json)); | 102 scoped_ptr<Value> parsed_value(base::JSONReader::Read(json)); |
102 if (!parsed_value.get() || !parsed_value->IsType(Value::TYPE_DICTIONARY)) | 103 if (!parsed_value.get() || !parsed_value->IsType(Value::TYPE_DICTIONARY)) |
103 return false; | 104 return false; |
104 | 105 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 if (!parsed_value.get() || !parsed_value->IsType(Value::TYPE_DICTIONARY)) | 170 if (!parsed_value.get() || !parsed_value->IsType(Value::TYPE_DICTIONARY)) |
170 return false; | 171 return false; |
171 | 172 |
172 DictionaryValue* result = static_cast<DictionaryValue*>(parsed_value.get()); | 173 DictionaryValue* result = static_cast<DictionaryValue*>(parsed_value.get()); |
173 return result->GetString("passphrase", passphrase); | 174 return result->GetString("passphrase", passphrase); |
174 } | 175 } |
175 | 176 |
176 string16 NormalizeUserName(const string16& user) { | 177 string16 NormalizeUserName(const string16& user) { |
177 if (user.find_first_of(ASCIIToUTF16("@")) != string16::npos) | 178 if (user.find_first_of(ASCIIToUTF16("@")) != string16::npos) |
178 return user; | 179 return user; |
179 return user + ASCIIToUTF16("@") + ASCIIToUTF16(DEFAULT_SIGNIN_DOMAIN); | 180 return user + ASCIIToUTF16("@") + ASCIIToUTF16(kDefaultSigninDomain); |
180 } | 181 } |
181 | 182 |
182 bool AreUserNamesEqual(const string16& user1, const string16& user2) { | 183 bool AreUserNamesEqual(const string16& user1, const string16& user2) { |
183 return NormalizeUserName(user1) == NormalizeUserName(user2); | 184 return NormalizeUserName(user1) == NormalizeUserName(user2); |
184 } | 185 } |
185 | 186 |
186 bool IsClientOAuthEnabled() { | 187 bool IsClientOAuthEnabled() { |
187 return CommandLine::ForCurrentProcess()->HasSwitch( | 188 return CommandLine::ForCurrentProcess()->HasSwitch( |
188 switches::kEnableClientOAuthSignin); | 189 switches::kEnableClientOAuthSignin); |
189 } | 190 } |
(...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1002 if (i != current_profile_index && AreUserNamesEqual( | 1003 if (i != current_profile_index && AreUserNamesEqual( |
1003 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { | 1004 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { |
1004 *error_message = l10n_util::GetStringUTF16( | 1005 *error_message = l10n_util::GetStringUTF16( |
1005 IDS_SYNC_USER_NAME_IN_USE_ERROR); | 1006 IDS_SYNC_USER_NAME_IN_USE_ERROR); |
1006 return false; | 1007 return false; |
1007 } | 1008 } |
1008 } | 1009 } |
1009 | 1010 |
1010 return true; | 1011 return true; |
1011 } | 1012 } |
OLD | NEW |