OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/media_galleries/fileapi/iphoto_data_provider.h" | 5 #include "chrome/browser/media_galleries/fileapi/iphoto_data_provider.h" |
6 | 6 |
| 7 #include <stdint.h> |
| 8 |
7 #include <map> | 9 #include <map> |
8 | 10 |
9 #include "base/bind.h" | 11 #include "base/bind.h" |
10 #include "base/callback.h" | 12 #include "base/callback.h" |
11 #include "base/location.h" | 13 #include "base/location.h" |
12 #include "base/logging.h" | 14 #include "base/logging.h" |
13 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
14 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
15 #include "base/threading/thread_restrictions.h" | 17 #include "base/threading/thread_restrictions.h" |
16 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" | 18 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" |
(...skipping 22 matching lines...) Expand all Loading... |
39 bool result, | 41 bool result, |
40 const parser::Library& library) { | 42 const parser::Library& library) { |
41 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); | 43 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); |
42 set_valid(result); | 44 set_valid(result); |
43 if (valid()) | 45 if (valid()) |
44 BuildIndices(library); | 46 BuildIndices(library); |
45 ready_callback.Run(valid()); | 47 ready_callback.Run(valid()); |
46 } | 48 } |
47 | 49 |
48 void IPhotoDataProvider::BuildIndices(const parser::Library& library) { | 50 void IPhotoDataProvider::BuildIndices(const parser::Library& library) { |
49 typedef base::hash_map<uint64, const base::FilePath*> IdIndex; | 51 typedef base::hash_map<uint64_t, const base::FilePath*> IdIndex; |
50 | 52 |
51 IdIndex photo_id_index; | 53 IdIndex photo_id_index; |
52 IdIndex originals_id_index; | 54 IdIndex originals_id_index; |
53 for (std::set<parser::Photo>::const_iterator photo_it = | 55 for (std::set<parser::Photo>::const_iterator photo_it = |
54 library.all_photos.begin(); | 56 library.all_photos.begin(); |
55 photo_it != library.all_photos.end(); photo_it++) { | 57 photo_it != library.all_photos.end(); photo_it++) { |
56 photo_id_index[photo_it->id] = &(photo_it->location); | 58 photo_id_index[photo_it->id] = &(photo_it->location); |
57 if (!photo_it->original_location.empty()) | 59 if (!photo_it->original_location.empty()) |
58 originals_id_index[photo_it->id] = &(photo_it->original_location); | 60 originals_id_index[photo_it->id] = &(photo_it->original_location); |
59 } | 61 } |
60 | 62 |
61 // Build up a set of IDs which have in-album duplicates. | 63 // Build up a set of IDs which have in-album duplicates. |
62 // Those are the filenames we want to globally mangle. | 64 // Those are the filenames we want to globally mangle. |
63 std::set<uint64> dupe_ids; | 65 std::set<uint64_t> dupe_ids; |
64 for (parser::Albums::const_iterator album_it = library.albums.begin(); | 66 for (parser::Albums::const_iterator album_it = library.albums.begin(); |
65 album_it != library.albums.end(); album_it++) { | 67 album_it != library.albums.end(); album_it++) { |
66 const parser::Album& album = album_it->second; | 68 const parser::Album& album = album_it->second; |
67 | 69 |
68 std::set<std::string> album_paths; | 70 std::set<std::string> album_paths; |
69 for (parser::Album::const_iterator id_it = album.begin(); | 71 for (parser::Album::const_iterator id_it = album.begin(); |
70 id_it != album.end(); id_it++) { | 72 id_it != album.end(); id_it++) { |
71 uint64 id = *id_it; | 73 uint64_t id = *id_it; |
72 IdIndex::const_iterator photo_it = photo_id_index.find(id); | 74 IdIndex::const_iterator photo_it = photo_id_index.find(id); |
73 if (photo_it == photo_id_index.end()) | 75 if (photo_it == photo_id_index.end()) |
74 continue; | 76 continue; |
75 | 77 |
76 std::string filename = photo_it->second->BaseName().value(); | 78 std::string filename = photo_it->second->BaseName().value(); |
77 if (ContainsKey(album_paths, filename)) | 79 if (ContainsKey(album_paths, filename)) |
78 dupe_ids.insert(id); | 80 dupe_ids.insert(id); |
79 else | 81 else |
80 album_paths.insert(filename); | 82 album_paths.insert(filename); |
81 } | 83 } |
82 } | 84 } |
83 | 85 |
84 // Now build the directory index. | 86 // Now build the directory index. |
85 dir_index_.clear(); | 87 dir_index_.clear(); |
86 originals_index_.clear(); | 88 originals_index_.clear(); |
87 for (parser::Albums::const_iterator album_it = library.albums.begin(); | 89 for (parser::Albums::const_iterator album_it = library.albums.begin(); |
88 album_it != library.albums.end(); album_it++) { | 90 album_it != library.albums.end(); album_it++) { |
89 std::string album_name = album_it->first; | 91 std::string album_name = album_it->first; |
90 const parser::Album& album = album_it->second; | 92 const parser::Album& album = album_it->second; |
91 | 93 |
92 for (parser::Album::const_iterator id_it = album.begin(); | 94 for (parser::Album::const_iterator id_it = album.begin(); |
93 id_it != album.end(); id_it++) { | 95 id_it != album.end(); id_it++) { |
94 uint64 id = *id_it; | 96 uint64_t id = *id_it; |
95 IdIndex::const_iterator photo_it = photo_id_index.find(id); | 97 IdIndex::const_iterator photo_it = photo_id_index.find(id); |
96 if (photo_it == photo_id_index.end()) | 98 if (photo_it == photo_id_index.end()) |
97 continue; | 99 continue; |
98 base::FilePath path = *(photo_it->second); | 100 base::FilePath path = *(photo_it->second); |
99 | 101 |
100 std::string filename = path.BaseName().value(); | 102 std::string filename = path.BaseName().value(); |
101 if (ContainsKey(dupe_ids, id)) { | 103 if (ContainsKey(dupe_ids, id)) { |
102 filename = path.BaseName().InsertBeforeExtension( | 104 filename = path.BaseName().InsertBeforeExtension( |
103 "(" + base::Uint64ToString(id) + ")").value(); | 105 "(" + base::Uint64ToString(id) + ")").value(); |
104 } | 106 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 DirIndex::const_iterator originals_it = originals_index_.find(album); | 178 DirIndex::const_iterator originals_it = originals_index_.find(album); |
177 if (originals_it == originals_index_.end()) | 179 if (originals_it == originals_index_.end()) |
178 return base::FilePath(); | 180 return base::FilePath(); |
179 FileIndex::const_iterator file_it = originals_it->second.find(filename); | 181 FileIndex::const_iterator file_it = originals_it->second.find(filename); |
180 if (file_it == originals_it->second.end()) | 182 if (file_it == originals_it->second.end()) |
181 return base::FilePath(); | 183 return base::FilePath(); |
182 return file_it->second; | 184 return file_it->second; |
183 } | 185 } |
184 | 186 |
185 } // namespace iphoto | 187 } // namespace iphoto |
OLD | NEW |