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

Side by Side Diff: chrome/browser/android/thumbnail/thumbnail_cache.cc

Issue 1708763003: Fix strict mode violation in TabPersistentStore.cleanupPersistentData() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@tab-persist-1
Patch Set: comments & rebase Created 4 years, 9 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
« no previous file with comments | « chrome/browser/android/thumbnail/thumbnail_cache.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/android/thumbnail/thumbnail_cache.h" 5 #include "chrome/browser/android/thumbnail/thumbnail_cache.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 thumbnail = approximation_cache_.Get(tab_id); 217 thumbnail = approximation_cache_.Get(tab_id);
218 if (thumbnail) { 218 if (thumbnail) {
219 thumbnail->CreateUIResource(); 219 thumbnail->CreateUIResource();
220 return thumbnail; 220 return thumbnail;
221 } 221 }
222 } 222 }
223 223
224 return NULL; 224 return NULL;
225 } 225 }
226 226
227 void ThumbnailCache::RemoveFromDiskAtAndAboveId(TabId min_id) {
228 base::Closure remove_task =
229 base::Bind(&ThumbnailCache::RemoveFromDiskAtAndAboveIdTask,
230 min_id);
231 content::BrowserThread::PostTask(
232 content::BrowserThread::FILE, FROM_HERE, remove_task);
233 }
234
235 void ThumbnailCache::InvalidateThumbnailIfChanged(TabId tab_id, 227 void ThumbnailCache::InvalidateThumbnailIfChanged(TabId tab_id,
236 const GURL& url) { 228 const GURL& url) {
237 ThumbnailMetaDataMap::iterator meta_data_iter = 229 ThumbnailMetaDataMap::iterator meta_data_iter =
238 thumbnail_meta_data_.find(tab_id); 230 thumbnail_meta_data_.find(tab_id);
239 if (meta_data_iter == thumbnail_meta_data_.end()) { 231 if (meta_data_iter == thumbnail_meta_data_.end()) {
240 thumbnail_meta_data_[tab_id] = ThumbnailMetaData(base::Time(), url); 232 thumbnail_meta_data_[tab_id] = ThumbnailMetaData(base::Time(), url);
241 } else if (meta_data_iter->second.url() != url) { 233 } else if (meta_data_iter->second.url() != url) {
242 Remove(tab_id); 234 Remove(tab_id);
243 } 235 }
244 } 236 }
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 content::BrowserThread::PostTask( 328 content::BrowserThread::PostTask(
337 content::BrowserThread::FILE, FROM_HERE, task); 329 content::BrowserThread::FILE, FROM_HERE, task);
338 } 330 }
339 331
340 void ThumbnailCache::RemoveFromDiskTask(TabId tab_id) { 332 void ThumbnailCache::RemoveFromDiskTask(TabId tab_id) {
341 base::FilePath file_path = GetFilePath(tab_id); 333 base::FilePath file_path = GetFilePath(tab_id);
342 if (base::PathExists(file_path)) 334 if (base::PathExists(file_path))
343 base::DeleteFile(file_path, false); 335 base::DeleteFile(file_path, false);
344 } 336 }
345 337
346 void ThumbnailCache::RemoveFromDiskAtAndAboveIdTask(TabId min_id) {
347 base::FilePath dir_path = GetCacheDirectory();
348 base::FileEnumerator enumerator(dir_path, false, base::FileEnumerator::FILES);
349 while (true) {
350 base::FilePath path = enumerator.Next();
351 if (path.empty())
352 break;
353 base::FileEnumerator::FileInfo info = enumerator.GetInfo();
354 TabId tab_id;
355 bool success = base::StringToInt(info.GetName().value(), &tab_id);
356 if (success && tab_id >= min_id)
357 base::DeleteFile(path, false);
358 }
359 }
360
361 void ThumbnailCache::WriteThumbnailIfNecessary( 338 void ThumbnailCache::WriteThumbnailIfNecessary(
362 TabId tab_id, 339 TabId tab_id,
363 skia::RefPtr<SkPixelRef> compressed_data, 340 skia::RefPtr<SkPixelRef> compressed_data,
364 float scale, 341 float scale,
365 const gfx::Size& content_size) { 342 const gfx::Size& content_size) {
366 if (write_tasks_count_ >= write_queue_max_size_) 343 if (write_tasks_count_ >= write_queue_max_size_)
367 return; 344 return;
368 345
369 write_tasks_count_++; 346 write_tasks_count_++;
370 347
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 dst_bitmap.eraseColor(0); 908 dst_bitmap.eraseColor(0);
932 SkAutoLockPixels dst_bitmap_lock(dst_bitmap); 909 SkAutoLockPixels dst_bitmap_lock(dst_bitmap);
933 910
934 SkCanvas canvas(dst_bitmap); 911 SkCanvas canvas(dst_bitmap);
935 canvas.scale(new_scale, new_scale); 912 canvas.scale(new_scale, new_scale);
936 canvas.drawBitmap(bitmap, 0, 0, NULL); 913 canvas.drawBitmap(bitmap, 0, 0, NULL);
937 dst_bitmap.setImmutable(); 914 dst_bitmap.setImmutable();
938 915
939 return std::make_pair(dst_bitmap, new_scale * scale); 916 return std::make_pair(dst_bitmap, new_scale * scale);
940 } 917 }
OLDNEW
« no previous file with comments | « chrome/browser/android/thumbnail/thumbnail_cache.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698