Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Side by Side Diff: chrome/browser/history/history_backend.cc

Issue 16296002: Update chrome/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/history/history_backend.h" 5 #include "chrome/browser/history/history_backend.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <list> 9 #include <list>
10 #include <map> 10 #include <map>
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 : history_backend_(history_backend) { 145 : history_backend_(history_backend) {
146 } 146 }
147 147
148 // The backend will call this function if it is being destroyed so that we 148 // The backend will call this function if it is being destroyed so that we
149 // release our reference. 149 // release our reference.
150 void Cancel() { 150 void Cancel() {
151 history_backend_ = NULL; 151 history_backend_ = NULL;
152 } 152 }
153 153
154 void RunCommit() { 154 void RunCommit() {
155 if (history_backend_) 155 if (history_backend_.get())
156 history_backend_->Commit(); 156 history_backend_->Commit();
157 } 157 }
158 158
159 private: 159 private:
160 friend class base::RefCounted<CommitLaterTask>; 160 friend class base::RefCounted<CommitLaterTask>;
161 161
162 ~CommitLaterTask() {} 162 ~CommitLaterTask() {}
163 163
164 scoped_refptr<HistoryBackend> history_backend_; 164 scoped_refptr<HistoryBackend> history_backend_;
165 }; 165 };
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 id_(id), 266 id_(id),
267 history_dir_(history_dir), 267 history_dir_(history_dir),
268 expirer_(this, bookmark_service), 268 expirer_(this, bookmark_service),
269 recent_redirects_(kMaxRedirectCount), 269 recent_redirects_(kMaxRedirectCount),
270 backend_destroy_message_loop_(NULL), 270 backend_destroy_message_loop_(NULL),
271 segment_queried_(false), 271 segment_queried_(false),
272 bookmark_service_(bookmark_service) { 272 bookmark_service_(bookmark_service) {
273 } 273 }
274 274
275 HistoryBackend::~HistoryBackend() { 275 HistoryBackend::~HistoryBackend() {
276 DCHECK(!scheduled_commit_) << "Deleting without cleanup"; 276 DCHECK(!scheduled_commit_.get()) << "Deleting without cleanup";
277 ReleaseDBTasks(); 277 ReleaseDBTasks();
278 278
279 #if defined(OS_ANDROID) 279 #if defined(OS_ANDROID)
280 // Release AndroidProviderBackend before other objects. 280 // Release AndroidProviderBackend before other objects.
281 android_provider_backend_.reset(); 281 android_provider_backend_.reset();
282 #endif 282 #endif
283 283
284 // First close the databases before optionally running the "destroy" task. 284 // First close the databases before optionally running the "destroy" task.
285 CloseAllDatabases(); 285 CloseAllDatabases();
286 286
(...skipping 2071 matching lines...) Expand 10 before | Expand all | Expand 10 after
2358 if (favicon_bitmaps_changed) 2358 if (favicon_bitmaps_changed)
2359 *favicon_bitmaps_changed = true; 2359 *favicon_bitmaps_changed = true;
2360 } 2360 }
2361 } 2361 }
2362 2362
2363 bool HistoryBackend::ValidateSetFaviconsParams( 2363 bool HistoryBackend::ValidateSetFaviconsParams(
2364 const std::vector<chrome::FaviconBitmapData>& favicon_bitmap_data) const { 2364 const std::vector<chrome::FaviconBitmapData>& favicon_bitmap_data) const {
2365 typedef std::map<GURL, size_t> BitmapsPerIconURL; 2365 typedef std::map<GURL, size_t> BitmapsPerIconURL;
2366 BitmapsPerIconURL num_bitmaps_per_icon_url; 2366 BitmapsPerIconURL num_bitmaps_per_icon_url;
2367 for (size_t i = 0; i < favicon_bitmap_data.size(); ++i) { 2367 for (size_t i = 0; i < favicon_bitmap_data.size(); ++i) {
2368 if (!favicon_bitmap_data[i].bitmap_data) 2368 if (!favicon_bitmap_data[i].bitmap_data.get())
2369 return false; 2369 return false;
2370 2370
2371 const GURL& icon_url = favicon_bitmap_data[i].icon_url; 2371 const GURL& icon_url = favicon_bitmap_data[i].icon_url;
2372 if (!num_bitmaps_per_icon_url.count(icon_url)) 2372 if (!num_bitmaps_per_icon_url.count(icon_url))
2373 num_bitmaps_per_icon_url[icon_url] = 1u; 2373 num_bitmaps_per_icon_url[icon_url] = 1u;
2374 else 2374 else
2375 ++num_bitmaps_per_icon_url[icon_url]; 2375 ++num_bitmaps_per_icon_url[icon_url];
2376 } 2376 }
2377 2377
2378 if (num_bitmaps_per_icon_url.size() > kMaxFaviconsPerPage) 2378 if (num_bitmaps_per_icon_url.size() > kMaxFaviconsPerPage)
2379 return false; 2379 return false;
2380 2380
2381 for (BitmapsPerIconURL::const_iterator it = num_bitmaps_per_icon_url.begin(); 2381 for (BitmapsPerIconURL::const_iterator it = num_bitmaps_per_icon_url.begin();
2382 it != num_bitmaps_per_icon_url.end(); ++it) { 2382 it != num_bitmaps_per_icon_url.end(); ++it) {
2383 if (it->second > kMaxFaviconBitmapsPerIconURL) 2383 if (it->second > kMaxFaviconBitmapsPerIconURL)
2384 return false; 2384 return false;
2385 } 2385 }
2386 return true; 2386 return true;
2387 } 2387 }
2388 2388
2389 bool HistoryBackend::IsFaviconBitmapDataEqual( 2389 bool HistoryBackend::IsFaviconBitmapDataEqual(
2390 FaviconBitmapID bitmap_id, 2390 FaviconBitmapID bitmap_id,
2391 const scoped_refptr<base::RefCountedMemory>& new_bitmap_data) { 2391 const scoped_refptr<base::RefCountedMemory>& new_bitmap_data) {
2392 if (!new_bitmap_data) 2392 if (!new_bitmap_data.get())
2393 return false; 2393 return false;
2394 2394
2395 scoped_refptr<base::RefCountedMemory> original_bitmap_data; 2395 scoped_refptr<base::RefCountedMemory> original_bitmap_data;
2396 thumbnail_db_->GetFaviconBitmap(bitmap_id, 2396 thumbnail_db_->GetFaviconBitmap(bitmap_id,
2397 NULL, 2397 NULL,
2398 &original_bitmap_data, 2398 &original_bitmap_data,
2399 NULL); 2399 NULL);
2400 return new_bitmap_data->Equals(original_bitmap_data); 2400 return new_bitmap_data->Equals(original_bitmap_data);
2401 } 2401 }
2402 2402
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
2641 archived_db_->BeginTransaction(); 2641 archived_db_->BeginTransaction();
2642 } 2642 }
2643 2643
2644 if (text_database_) { 2644 if (text_database_) {
2645 text_database_->CommitTransaction(); 2645 text_database_->CommitTransaction();
2646 text_database_->BeginTransaction(); 2646 text_database_->BeginTransaction();
2647 } 2647 }
2648 } 2648 }
2649 2649
2650 void HistoryBackend::ScheduleCommit() { 2650 void HistoryBackend::ScheduleCommit() {
2651 if (scheduled_commit_) 2651 if (scheduled_commit_.get())
2652 return; 2652 return;
2653 scheduled_commit_ = new CommitLaterTask(this); 2653 scheduled_commit_ = new CommitLaterTask(this);
2654 base::MessageLoop::current()->PostDelayedTask( 2654 base::MessageLoop::current()->PostDelayedTask(
2655 FROM_HERE, 2655 FROM_HERE,
2656 base::Bind(&CommitLaterTask::RunCommit, scheduled_commit_.get()), 2656 base::Bind(&CommitLaterTask::RunCommit, scheduled_commit_.get()),
2657 base::TimeDelta::FromSeconds(kCommitIntervalSeconds)); 2657 base::TimeDelta::FromSeconds(kCommitIntervalSeconds));
2658 } 2658 }
2659 2659
2660 void HistoryBackend::CancelScheduledCommit() { 2660 void HistoryBackend::CancelScheduledCommit() {
2661 if (scheduled_commit_) { 2661 if (scheduled_commit_.get()) {
2662 scheduled_commit_->Cancel(); 2662 scheduled_commit_->Cancel();
2663 scheduled_commit_ = NULL; 2663 scheduled_commit_ = NULL;
2664 } 2664 }
2665 } 2665 }
2666 2666
2667 void HistoryBackend::ProcessDBTaskImpl() { 2667 void HistoryBackend::ProcessDBTaskImpl() {
2668 if (!db_) { 2668 if (!db_) {
2669 // db went away, release all the refs. 2669 // db went away, release all the refs.
2670 ReleaseDBTasks(); 2670 ReleaseDBTasks();
2671 return; 2671 return;
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
2863 // databases which will be closed. 2863 // databases which will be closed.
2864 expirer_.SetDatabases(NULL, NULL, NULL, NULL); 2864 expirer_.SetDatabases(NULL, NULL, NULL, NULL);
2865 2865
2866 // Reopen a new transaction for |db_| for the sake of CloseAllDatabases(). 2866 // Reopen a new transaction for |db_| for the sake of CloseAllDatabases().
2867 db_->BeginTransaction(); 2867 db_->BeginTransaction();
2868 CloseAllDatabases(); 2868 CloseAllDatabases();
2869 } 2869 }
2870 2870
2871 void HistoryBackend::ProcessDBTask( 2871 void HistoryBackend::ProcessDBTask(
2872 scoped_refptr<HistoryDBTaskRequest> request) { 2872 scoped_refptr<HistoryDBTaskRequest> request) {
2873 DCHECK(request); 2873 DCHECK(request.get());
2874 if (request->canceled()) 2874 if (request->canceled())
2875 return; 2875 return;
2876 2876
2877 bool task_scheduled = !db_task_requests_.empty(); 2877 bool task_scheduled = !db_task_requests_.empty();
2878 // Make sure we up the refcount of the request. ProcessDBTaskImpl will 2878 // Make sure we up the refcount of the request. ProcessDBTaskImpl will
2879 // release when done with the task. 2879 // release when done with the task.
2880 request->AddRef(); 2880 request->AddRef();
2881 db_task_requests_.push_back(request.get()); 2881 db_task_requests_.push_back(request.get());
2882 if (!task_scheduled) { 2882 if (!task_scheduled) {
2883 // No other tasks are scheduled. Process request now. 2883 // No other tasks are scheduled. Process request now.
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
3098 info.url_id = visit.url_id; 3098 info.url_id = visit.url_id;
3099 info.time = visit.visit_time; 3099 info.time = visit.visit_time;
3100 info.transition = visit.transition; 3100 info.transition = visit.transition;
3101 // If we don't have a delegate yet during setup or shutdown, we will drop 3101 // If we don't have a delegate yet during setup or shutdown, we will drop
3102 // these notifications. 3102 // these notifications.
3103 if (delegate_) 3103 if (delegate_)
3104 delegate_->NotifyVisitDBObserversOnAddVisit(info); 3104 delegate_->NotifyVisitDBObserversOnAddVisit(info);
3105 } 3105 }
3106 3106
3107 } // namespace history 3107 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/google_apis/gdata_wapi_operations_unittest.cc ('k') | chrome/browser/history/history_backend_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698