| OLD | NEW |
| 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 "storage/browser/blob/shareable_file_reference.h" | 5 #include "storage/browser/blob/shareable_file_reference.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 void Erase(key_type key) { | 48 void Erase(key_type key) { |
| 49 DCHECK(CalledOnValidThread()); | 49 DCHECK(CalledOnValidThread()); |
| 50 file_map_.erase(key); | 50 file_map_.erase(key); |
| 51 } | 51 } |
| 52 | 52 |
| 53 private: | 53 private: |
| 54 FileMap file_map_; | 54 FileMap file_map_; |
| 55 DISALLOW_COPY_AND_ASSIGN(ShareableFileMap); | 55 DISALLOW_COPY_AND_ASSIGN(ShareableFileMap); |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 base::LazyInstance<ShareableFileMap> g_file_map = LAZY_INSTANCE_INITIALIZER; | 58 base::LazyInstance<ShareableFileMap>::DestructorAtExit g_file_map = |
| 59 LAZY_INSTANCE_INITIALIZER; |
| 59 | 60 |
| 60 } // namespace | 61 } // namespace |
| 61 | 62 |
| 62 // static | 63 // static |
| 63 scoped_refptr<ShareableFileReference> ShareableFileReference::Get( | 64 scoped_refptr<ShareableFileReference> ShareableFileReference::Get( |
| 64 const base::FilePath& path) { | 65 const base::FilePath& path) { |
| 65 ShareableFileMap::iterator found = g_file_map.Get().Find(path); | 66 ShareableFileMap::iterator found = g_file_map.Get().Find(path); |
| 66 ShareableFileReference* reference = | 67 ShareableFileReference* reference = |
| 67 (found == g_file_map.Get().End()) ? NULL : found->second; | 68 (found == g_file_map.Get().End()) ? NULL : found->second; |
| 68 return scoped_refptr<ShareableFileReference>(reference); | 69 return scoped_refptr<ShareableFileReference>(reference); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 : scoped_file_(std::move(scoped_file)) { | 114 : scoped_file_(std::move(scoped_file)) { |
| 114 DCHECK(g_file_map.Get().Find(path())->second == NULL); | 115 DCHECK(g_file_map.Get().Find(path())->second == NULL); |
| 115 } | 116 } |
| 116 | 117 |
| 117 ShareableFileReference::~ShareableFileReference() { | 118 ShareableFileReference::~ShareableFileReference() { |
| 118 DCHECK(g_file_map.Get().Find(path())->second == this); | 119 DCHECK(g_file_map.Get().Find(path())->second == this); |
| 119 g_file_map.Get().Erase(path()); | 120 g_file_map.Get().Erase(path()); |
| 120 } | 121 } |
| 121 | 122 |
| 122 } // namespace storage | 123 } // namespace storage |
| OLD | NEW |