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

Side by Side Diff: chrome/browser/download/download_path_reservation_tracker.cc

Issue 2845293004: Switch SupportsUserData uses to use unique_ptr. (Closed)
Patch Set: Created 3 years, 7 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
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/download/download_path_reservation_tracker.h" 5 #include "chrome/browser/download/download_path_reservation_tracker.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/files/file_util.h" 15 #include "base/files/file_util.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/memory/ptr_util.h"
18 #include "base/path_service.h" 19 #include "base/path_service.h"
19 #include "base/stl_util.h" 20 #include "base/stl_util.h"
20 #include "base/strings/string_util.h" 21 #include "base/strings/string_util.h"
21 #include "base/strings/stringprintf.h" 22 #include "base/strings/stringprintf.h"
22 #include "base/third_party/icu/icu_utf.h" 23 #include "base/third_party/icu/icu_utf.h"
23 #include "build/build_config.h" 24 #include "build/build_config.h"
24 #include "chrome/common/chrome_paths.h" 25 #include "chrome/common/chrome_paths.h"
25 #include "chrome/common/features.h" 26 #include "chrome/common/features.h"
26 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
27 #include "content/public/browser/download_item.h" 28 #include "content/public/browser/download_item.h"
(...skipping 27 matching lines...) Expand all
55 // that is supposed to overwrite an existing reservation. 56 // that is supposed to overwrite an existing reservation.
56 ReservationMap* g_reservation_map = NULL; 57 ReservationMap* g_reservation_map = NULL;
57 58
58 // Observes a DownloadItem for changes to its target path and state. Updates or 59 // Observes a DownloadItem for changes to its target path and state. Updates or
59 // revokes associated download path reservations as necessary. Created, invoked 60 // revokes associated download path reservations as necessary. Created, invoked
60 // and destroyed on the UI thread. 61 // and destroyed on the UI thread.
61 class DownloadItemObserver : public DownloadItem::Observer, 62 class DownloadItemObserver : public DownloadItem::Observer,
62 public base::SupportsUserData::Data { 63 public base::SupportsUserData::Data {
63 public: 64 public:
64 explicit DownloadItemObserver(DownloadItem* download_item); 65 explicit DownloadItemObserver(DownloadItem* download_item);
66 ~DownloadItemObserver() override;
65 67
66 private: 68 private:
67 ~DownloadItemObserver() override;
68
69 // DownloadItem::Observer 69 // DownloadItem::Observer
70 void OnDownloadUpdated(DownloadItem* download) override; 70 void OnDownloadUpdated(DownloadItem* download) override;
71 void OnDownloadDestroyed(DownloadItem* download) override; 71 void OnDownloadDestroyed(DownloadItem* download) override;
72 72
73 DownloadItem* download_item_; 73 DownloadItem* download_item_;
74 74
75 // Last known target path for the download. 75 // Last known target path for the download.
76 base::FilePath last_target_path_; 76 base::FilePath last_target_path_;
77 77
78 static const int kUserDataKey; 78 static const int kUserDataKey;
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 PathValidationResult result) { 331 PathValidationResult result) {
332 DCHECK_CURRENTLY_ON(BrowserThread::UI); 332 DCHECK_CURRENTLY_ON(BrowserThread::UI);
333 callback.Run(result, *reserved_path); 333 callback.Run(result, *reserved_path);
334 } 334 }
335 335
336 DownloadItemObserver::DownloadItemObserver(DownloadItem* download_item) 336 DownloadItemObserver::DownloadItemObserver(DownloadItem* download_item)
337 : download_item_(download_item), 337 : download_item_(download_item),
338 last_target_path_(download_item->GetTargetFilePath()) { 338 last_target_path_(download_item->GetTargetFilePath()) {
339 DCHECK_CURRENTLY_ON(BrowserThread::UI); 339 DCHECK_CURRENTLY_ON(BrowserThread::UI);
340 download_item_->AddObserver(this); 340 download_item_->AddObserver(this);
341 download_item_->SetUserData(&kUserDataKey, this); 341 download_item_->SetUserData(&kUserDataKey, base::WrapUnique(this));
342 } 342 }
343 343
344 DownloadItemObserver::~DownloadItemObserver() { 344 DownloadItemObserver::~DownloadItemObserver() {
345 download_item_->RemoveObserver(this); 345 download_item_->RemoveObserver(this);
346 // DownloadItemObserver is owned by DownloadItem. It should only be getting 346 // DownloadItemObserver is owned by DownloadItem. It should only be getting
347 // destroyed because it's being removed from the UserData pool. No need to 347 // destroyed because it's being removed from the UserData pool. No need to
348 // call DownloadItem::RemoveUserData(). 348 // call DownloadItem::RemoveUserData().
349 } 349 }
350 350
351 void DownloadItemObserver::OnDownloadUpdated(DownloadItem* download) { 351 void DownloadItemObserver::OnDownloadUpdated(DownloadItem* download) {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 base::Bind(&CreateReservation, info, reserved_path), 429 base::Bind(&CreateReservation, info, reserved_path),
430 base::Bind(&RunGetReservedPathCallback, callback, 430 base::Bind(&RunGetReservedPathCallback, callback,
431 base::Owned(reserved_path))); 431 base::Owned(reserved_path)));
432 } 432 }
433 433
434 // static 434 // static
435 bool DownloadPathReservationTracker::IsPathInUseForTesting( 435 bool DownloadPathReservationTracker::IsPathInUseForTesting(
436 const base::FilePath& path) { 436 const base::FilePath& path) {
437 return IsPathInUse(path); 437 return IsPathInUse(path);
438 } 438 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_item_model.cc ('k') | chrome/browser/download/download_status_updater.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698