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" |
11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
12 #include "base/string_split.h" | 12 #include "base/string_split.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "chrome/browser/first_run/first_run.h" | 14 #include "chrome/browser/first_run/first_run.h" |
15 #include "chrome/browser/importer/importer_bridge.h" | 15 #include "chrome/browser/importer/importer_bridge.h" |
16 #include "chrome/browser/importer/importer_data_types.h" | 16 #include "chrome/browser/importer/importer_data_types.h" |
17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/common/libxml_utils.h" | 18 #include "chrome/common/libxml_utils.h" |
19 #include "content/browser/browser_thread.h" | 19 #include "content/browser/browser_thread.h" |
| 20 #include "content/common/net/url_fetcher.h" |
20 #include "grit/generated_resources.h" | 21 #include "grit/generated_resources.h" |
21 | 22 |
22 // Toolbar5Importer | 23 // Toolbar5Importer |
23 const char Toolbar5Importer::kXmlApiReplyXmlTag[] = "xml_api_reply"; | 24 const char Toolbar5Importer::kXmlApiReplyXmlTag[] = "xml_api_reply"; |
24 const char Toolbar5Importer::kBookmarksXmlTag[] = "bookmarks"; | 25 const char Toolbar5Importer::kBookmarksXmlTag[] = "bookmarks"; |
25 const char Toolbar5Importer::kBookmarkXmlTag[] = "bookmark"; | 26 const char Toolbar5Importer::kBookmarkXmlTag[] = "bookmark"; |
26 const char Toolbar5Importer::kTitleXmlTag[] = "title"; | 27 const char Toolbar5Importer::kTitleXmlTag[] = "title"; |
27 const char Toolbar5Importer::kUrlXmlTag[] = "url"; | 28 const char Toolbar5Importer::kUrlXmlTag[] = "url"; |
28 const char Toolbar5Importer::kTimestampXmlTag[] = "timestamp"; | 29 const char Toolbar5Importer::kTimestampXmlTag[] = "timestamp"; |
29 const char Toolbar5Importer::kLabelsXmlTag[] = "labels"; | 30 const char Toolbar5Importer::kLabelsXmlTag[] = "labels"; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 // thread for synchronization. | 90 // thread for synchronization. |
90 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 91 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
91 EndImport(); | 92 EndImport(); |
92 } else { | 93 } else { |
93 BrowserThread::PostTask( | 94 BrowserThread::PostTask( |
94 BrowserThread::UI, FROM_HERE, | 95 BrowserThread::UI, FROM_HERE, |
95 base::Bind(&Toolbar5Importer::Cancel, this)); | 96 base::Bind(&Toolbar5Importer::Cancel, this)); |
96 } | 97 } |
97 } | 98 } |
98 | 99 |
99 void Toolbar5Importer::OnURLFetchComplete( | 100 void Toolbar5Importer::OnURLFetchComplete(const URLFetcher* source) { |
100 const URLFetcher* source, | |
101 const GURL& url, | |
102 const net::URLRequestStatus& status, | |
103 int response_code, | |
104 const net::ResponseCookies& cookies, | |
105 const std::string& data) { | |
106 if (cancelled()) { | 101 if (cancelled()) { |
107 EndImport(); | 102 EndImport(); |
108 return; | 103 return; |
109 } | 104 } |
110 | 105 |
111 if (200 != response_code) { // HTTP/Ok | 106 if (200 != source->response_code()) { // HTTP/Ok |
112 // 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 |
113 // import. | 108 // import. |
114 EndImportBookmarks(); | 109 EndImportBookmarks(); |
115 return; | 110 return; |
116 } | 111 } |
117 | 112 |
| 113 std::string data; |
| 114 source->GetResponseAsString(&data); |
118 switch (state_) { | 115 switch (state_) { |
119 case GET_AUTHORIZATION_TOKEN: | 116 case GET_AUTHORIZATION_TOKEN: |
120 GetBookmarkDataFromServer(data); | 117 GetBookmarkDataFromServer(data); |
121 break; | 118 break; |
122 case GET_BOOKMARKS: | 119 case GET_BOOKMARKS: |
123 GetBookmarksFromServerDataResponse(data); | 120 GetBookmarksFromServerDataResponse(data); |
124 break; | 121 break; |
125 default: | 122 default: |
126 NOTREACHED() << "Invalid state."; | 123 NOTREACHED() << "Invalid state."; |
127 EndImportBookmarks(); | 124 EndImportBookmarks(); |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 } | 552 } |
556 | 553 |
557 void Toolbar5Importer::AddBookmarksToChrome( | 554 void Toolbar5Importer::AddBookmarksToChrome( |
558 const std::vector<ProfileWriter::BookmarkEntry>& bookmarks) { | 555 const std::vector<ProfileWriter::BookmarkEntry>& bookmarks) { |
559 if (!bookmarks.empty() && !cancelled()) { | 556 if (!bookmarks.empty() && !cancelled()) { |
560 const string16& first_folder_name = | 557 const string16& first_folder_name = |
561 bridge_->GetLocalizedString(IDS_BOOKMARK_GROUP_FROM_GOOGLE_TOOLBAR); | 558 bridge_->GetLocalizedString(IDS_BOOKMARK_GROUP_FROM_GOOGLE_TOOLBAR); |
562 bridge_->AddBookmarks(bookmarks, first_folder_name); | 559 bridge_->AddBookmarks(bookmarks, first_folder_name); |
563 } | 560 } |
564 } | 561 } |
OLD | NEW |