| 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/bookmarks/bookmark_html_writer.h" | 5 #include "chrome/browser/bookmarks/bookmark_html_writer.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/platform_file.h" | 12 #include "base/platform_file.h" |
| 13 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
| 14 #include "base/time.h" | 14 #include "base/time.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "chrome/browser/bookmarks/bookmark_codec.h" | 16 #include "chrome/browser/bookmarks/bookmark_codec.h" |
| 17 #include "chrome/browser/bookmarks/bookmark_model.h" | 17 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 18 #include "chrome/browser/history/history_types.h" | 18 #include "chrome/browser/history/history_types.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/common/chrome_notification_types.h" |
| 20 #include "content/browser/browser_thread.h" | 21 #include "content/browser/browser_thread.h" |
| 21 #include "content/common/notification_source.h" | 22 #include "content/common/notification_source.h" |
| 22 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
| 23 #include "net/base/escape.h" | 24 #include "net/base/escape.h" |
| 24 #include "net/base/file_stream.h" | 25 #include "net/base/file_stream.h" |
| 25 #include "net/base/net_errors.h" | 26 #include "net/base/net_errors.h" |
| 26 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
| 27 | 28 |
| 28 namespace { | 29 namespace { |
| 29 | 30 |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 | 375 |
| 375 BookmarkFaviconFetcher::BookmarkFaviconFetcher( | 376 BookmarkFaviconFetcher::BookmarkFaviconFetcher( |
| 376 Profile* profile, | 377 Profile* profile, |
| 377 const FilePath& path, | 378 const FilePath& path, |
| 378 BookmarksExportObserver* observer) | 379 BookmarksExportObserver* observer) |
| 379 : profile_(profile), | 380 : profile_(profile), |
| 380 path_(path), | 381 path_(path), |
| 381 observer_(observer) { | 382 observer_(observer) { |
| 382 favicons_map_.reset(new URLFaviconMap()); | 383 favicons_map_.reset(new URLFaviconMap()); |
| 383 registrar_.Add(this, | 384 registrar_.Add(this, |
| 384 NotificationType::PROFILE_DESTROYED, | 385 chrome::NOTIFICATION_PROFILE_DESTROYED, |
| 385 Source<Profile>(profile_)); | 386 Source<Profile>(profile_)); |
| 386 } | 387 } |
| 387 | 388 |
| 388 BookmarkFaviconFetcher::~BookmarkFaviconFetcher() { | 389 BookmarkFaviconFetcher::~BookmarkFaviconFetcher() { |
| 389 } | 390 } |
| 390 | 391 |
| 391 void BookmarkFaviconFetcher::ExportBookmarks() { | 392 void BookmarkFaviconFetcher::ExportBookmarks() { |
| 392 ExtractUrls(profile_->GetBookmarkModel()->GetBookmarkBarNode()); | 393 ExtractUrls(profile_->GetBookmarkModel()->GetBookmarkBarNode()); |
| 393 ExtractUrls(profile_->GetBookmarkModel()->other_node()); | 394 ExtractUrls(profile_->GetBookmarkModel()->other_node()); |
| 394 ExtractUrls(profile_->GetBookmarkModel()->synced_node()); | 395 ExtractUrls(profile_->GetBookmarkModel()->synced_node()); |
| 395 if (!bookmark_urls_.empty()) { | 396 if (!bookmark_urls_.empty()) { |
| 396 FetchNextFavicon(); | 397 FetchNextFavicon(); |
| 397 } else { | 398 } else { |
| 398 ExecuteWriter(); | 399 ExecuteWriter(); |
| 399 } | 400 } |
| 400 } | 401 } |
| 401 | 402 |
| 402 void BookmarkFaviconFetcher::Observe(NotificationType type, | 403 void BookmarkFaviconFetcher::Observe(int type, |
| 403 const NotificationSource& source, | 404 const NotificationSource& source, |
| 404 const NotificationDetails& details) { | 405 const NotificationDetails& details) { |
| 405 if (NotificationType::PROFILE_DESTROYED == type && fetcher != NULL) { | 406 if (chrome::NOTIFICATION_PROFILE_DESTROYED == type && fetcher != NULL) { |
| 406 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher); | 407 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher); |
| 407 fetcher = NULL; | 408 fetcher = NULL; |
| 408 } | 409 } |
| 409 } | 410 } |
| 410 | 411 |
| 411 void BookmarkFaviconFetcher::ExtractUrls(const BookmarkNode* node) { | 412 void BookmarkFaviconFetcher::ExtractUrls(const BookmarkNode* node) { |
| 412 if (BookmarkNode::URL == node->type()) { | 413 if (BookmarkNode::URL == node->type()) { |
| 413 std::string url = node->GetURL().spec(); | 414 std::string url = node->GetURL().spec(); |
| 414 if (!url.empty()) { | 415 if (!url.empty()) { |
| 415 bookmark_urls_.push_back(url); | 416 bookmark_urls_.push_back(url); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 // BookmarkModel isn't thread safe (nor would we want to lock it down | 486 // BookmarkModel isn't thread safe (nor would we want to lock it down |
| 486 // for the duration of the write), as such we make a copy of the | 487 // for the duration of the write), as such we make a copy of the |
| 487 // BookmarkModel using BookmarkCodec then write from that. | 488 // BookmarkModel using BookmarkCodec then write from that. |
| 488 if (fetcher == NULL) { | 489 if (fetcher == NULL) { |
| 489 fetcher = new BookmarkFaviconFetcher(profile, path, observer); | 490 fetcher = new BookmarkFaviconFetcher(profile, path, observer); |
| 490 fetcher->ExportBookmarks(); | 491 fetcher->ExportBookmarks(); |
| 491 } | 492 } |
| 492 } | 493 } |
| 493 | 494 |
| 494 } // namespace bookmark_html_writer | 495 } // namespace bookmark_html_writer |
| OLD | NEW |