| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "webkit/blob/deletable_file_reference.h" | 5 #include "webkit/blob/deletable_file_reference.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/file_util_proxy.h" | 9 #include "base/file_util_proxy.h" |
| 10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 scoped_refptr<DeletableFileReference> DeletableFileReference::GetOrCreate( | 35 scoped_refptr<DeletableFileReference> DeletableFileReference::GetOrCreate( |
| 36 const FilePath& path, base::MessageLoopProxy* file_thread) { | 36 const FilePath& path, base::MessageLoopProxy* file_thread) { |
| 37 DCHECK(file_thread); | 37 DCHECK(file_thread); |
| 38 typedef std::pair<DeleteableFileMap::iterator, bool> InsertResult; | 38 typedef std::pair<DeleteableFileMap::iterator, bool> InsertResult; |
| 39 InsertResult result = map()->insert( | 39 InsertResult result = map()->insert( |
| 40 DeleteableFileMap::value_type(path, NULL)); | 40 DeleteableFileMap::value_type(path, NULL)); |
| 41 if (result.second == false) | 41 if (result.second == false) |
| 42 return scoped_refptr<DeletableFileReference>(result.first->second); | 42 return scoped_refptr<DeletableFileReference>(result.first->second); |
| 43 | 43 |
| 44 // Wasn't in the map, create a new reference and store the pointer. | 44 // Wasn't in the map, create a new reference and store the pointer. |
| 45 scoped_refptr<DeletableFileReference> reference = | 45 scoped_refptr<DeletableFileReference> reference( |
| 46 new DeletableFileReference(path, file_thread); | 46 new DeletableFileReference(path, file_thread)); |
| 47 result.first->second = reference.get(); | 47 result.first->second = reference.get(); |
| 48 return reference; | 48 return reference; |
| 49 } | 49 } |
| 50 | 50 |
| 51 DeletableFileReference::DeletableFileReference( | 51 DeletableFileReference::DeletableFileReference( |
| 52 const FilePath& path, base::MessageLoopProxy* file_thread) | 52 const FilePath& path, base::MessageLoopProxy* file_thread) |
| 53 : path_(path), file_thread_(file_thread) { | 53 : path_(path), file_thread_(file_thread) { |
| 54 DCHECK(map()->find(path_)->second == NULL); | 54 DCHECK(map()->find(path_)->second == NULL); |
| 55 } | 55 } |
| 56 | 56 |
| 57 DeletableFileReference::~DeletableFileReference() { | 57 DeletableFileReference::~DeletableFileReference() { |
| 58 DCHECK(map()->find(path_)->second == this); | 58 DCHECK(map()->find(path_)->second == this); |
| 59 map()->erase(path_); | 59 map()->erase(path_); |
| 60 base::FileUtilProxy::Delete(file_thread_, path_, false /* recursive */, NULL); | 60 base::FileUtilProxy::Delete(file_thread_, path_, false /* recursive */, NULL); |
| 61 } | 61 } |
| 62 | 62 |
| 63 } // namespace webkit_blob | 63 } // namespace webkit_blob |
| OLD | NEW |