| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/importer/toolbar_importer.h" | 5 #include "chrome/browser/importer/toolbar_importer.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 // thread for synchronization. | 90 // thread for synchronization. |
| 91 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 91 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 92 EndImport(); | 92 EndImport(); |
| 93 } else { | 93 } else { |
| 94 BrowserThread::PostTask( | 94 BrowserThread::PostTask( |
| 95 BrowserThread::UI, FROM_HERE, | 95 BrowserThread::UI, FROM_HERE, |
| 96 base::Bind(&Toolbar5Importer::Cancel, this)); | 96 base::Bind(&Toolbar5Importer::Cancel, this)); |
| 97 } | 97 } |
| 98 } | 98 } |
| 99 | 99 |
| 100 void Toolbar5Importer::OnURLFetchComplete(const URLFetcher* source) { | 100 void Toolbar5Importer::OnURLFetchComplete(const content::URLFetcher* source) { |
| 101 if (cancelled()) { | 101 if (cancelled()) { |
| 102 EndImport(); | 102 EndImport(); |
| 103 return; | 103 return; |
| 104 } | 104 } |
| 105 | 105 |
| 106 if (200 != source->response_code()) { // HTTP/Ok | 106 if (200 != source->GetResponseCode()) { // HTTP/Ok |
| 107 // Cancelling here will update the UI and bypass the rest of bookmark | 107 // Cancelling here will update the UI and bypass the rest of bookmark |
| 108 // import. | 108 // import. |
| 109 EndImportBookmarks(); | 109 EndImportBookmarks(); |
| 110 return; | 110 return; |
| 111 } | 111 } |
| 112 | 112 |
| 113 std::string data; | 113 std::string data; |
| 114 source->GetResponseAsString(&data); | 114 source->GetResponseAsString(&data); |
| 115 switch (state_) { | 115 switch (state_) { |
| 116 case GET_AUTHORIZATION_TOKEN: | 116 case GET_AUTHORIZATION_TOKEN: |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 std::string random_string = base::UintToString(random); | 200 std::string random_string = base::UintToString(random); |
| 201 | 201 |
| 202 // Retrieve authorization token from the network. | 202 // Retrieve authorization token from the network. |
| 203 std::string url_string(kT5AuthorizationTokenUrl); | 203 std::string url_string(kT5AuthorizationTokenUrl); |
| 204 url_string.replace(url_string.find(kRandomNumberToken), | 204 url_string.replace(url_string.find(kRandomNumberToken), |
| 205 arraysize(kRandomNumberToken) - 1, | 205 arraysize(kRandomNumberToken) - 1, |
| 206 random_string); | 206 random_string); |
| 207 GURL url(url_string); | 207 GURL url(url_string); |
| 208 | 208 |
| 209 token_fetcher_ = new URLFetcher(url, URLFetcher::GET, this); | 209 token_fetcher_ = new URLFetcher(url, URLFetcher::GET, this); |
| 210 token_fetcher_->set_request_context( | 210 token_fetcher_->SetRequestContext( |
| 211 Profile::Deprecated::GetDefaultRequestContext()); | 211 Profile::Deprecated::GetDefaultRequestContext()); |
| 212 token_fetcher_->Start(); | 212 token_fetcher_->Start(); |
| 213 } | 213 } |
| 214 | 214 |
| 215 void Toolbar5Importer::GetBookmarkDataFromServer(const std::string& response) { | 215 void Toolbar5Importer::GetBookmarkDataFromServer(const std::string& response) { |
| 216 if (cancelled()) { | 216 if (cancelled()) { |
| 217 EndImport(); | 217 EndImport(); |
| 218 return; | 218 return; |
| 219 } | 219 } |
| 220 | 220 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 234 std::string random_string = base::UintToString(random); | 234 std::string random_string = base::UintToString(random); |
| 235 conn_string.replace(conn_string.find(kRandomNumberToken), | 235 conn_string.replace(conn_string.find(kRandomNumberToken), |
| 236 arraysize(kRandomNumberToken) - 1, | 236 arraysize(kRandomNumberToken) - 1, |
| 237 random_string); | 237 random_string); |
| 238 conn_string.replace(conn_string.find(kAuthorizationToken), | 238 conn_string.replace(conn_string.find(kAuthorizationToken), |
| 239 arraysize(kAuthorizationToken) - 1, | 239 arraysize(kAuthorizationToken) - 1, |
| 240 token); | 240 token); |
| 241 GURL url(conn_string); | 241 GURL url(conn_string); |
| 242 | 242 |
| 243 data_fetcher_ = new URLFetcher(url, URLFetcher::GET, this); | 243 data_fetcher_ = new URLFetcher(url, URLFetcher::GET, this); |
| 244 data_fetcher_->set_request_context( | 244 data_fetcher_->SetRequestContext( |
| 245 Profile::Deprecated::GetDefaultRequestContext()); | 245 Profile::Deprecated::GetDefaultRequestContext()); |
| 246 data_fetcher_->Start(); | 246 data_fetcher_->Start(); |
| 247 } | 247 } |
| 248 | 248 |
| 249 void Toolbar5Importer::GetBookmarksFromServerDataResponse( | 249 void Toolbar5Importer::GetBookmarksFromServerDataResponse( |
| 250 const std::string& response) { | 250 const std::string& response) { |
| 251 if (cancelled()) { | 251 if (cancelled()) { |
| 252 EndImport(); | 252 EndImport(); |
| 253 return; | 253 return; |
| 254 } | 254 } |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 } | 552 } |
| 553 | 553 |
| 554 void Toolbar5Importer::AddBookmarksToChrome( | 554 void Toolbar5Importer::AddBookmarksToChrome( |
| 555 const std::vector<ProfileWriter::BookmarkEntry>& bookmarks) { | 555 const std::vector<ProfileWriter::BookmarkEntry>& bookmarks) { |
| 556 if (!bookmarks.empty() && !cancelled()) { | 556 if (!bookmarks.empty() && !cancelled()) { |
| 557 const string16& first_folder_name = | 557 const string16& first_folder_name = |
| 558 bridge_->GetLocalizedString(IDS_BOOKMARK_GROUP_FROM_GOOGLE_TOOLBAR); | 558 bridge_->GetLocalizedString(IDS_BOOKMARK_GROUP_FROM_GOOGLE_TOOLBAR); |
| 559 bridge_->AddBookmarks(bookmarks, first_folder_name); | 559 bridge_->AddBookmarks(bookmarks, first_folder_name); |
| 560 } | 560 } |
| 561 } | 561 } |
| OLD | NEW |