1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ios/chrome/browser/snapshots/snapshots_util.h"
7 #import <UIKit/UIKit.h>
9 #include "base/files/file_util.h"
10 #include "base/ios/ios_util.h"
11 #include "base/location.h"
12 #include "base/mac/foundation_util.h"
13 #include "base/path_service.h"
14 #include "base/strings/stringprintf.h"
15 #include "ios/web/public/web_thread.h"
18 const char* kOrientationDescriptions[] = {
26 void ClearIOSSnapshots() {
27 // Generates a list containing all the possible snapshot paths because the
28 // list of snapshots stored on the device can't be obtained programmatically.
29 std::vector<base::FilePath> snapshotsPaths;
30 GetSnapshotsPaths(&snapshotsPaths);
31 for (base::FilePath snapshotPath : snapshotsPaths) {
32 web::WebThread::PostBlockingPoolTask(
34 base::Bind(base::IgnoreResult(&base::DeleteFile), snapshotPath, false));
38 void GetSnapshotsPaths(std::vector<base::FilePath>* snapshotsPaths) {
39 DCHECK(snapshotsPaths);
40 base::FilePath snapshotsDir;
41 PathService::Get(base::DIR_CACHE, &snapshotsDir);
43 snapshotsDir.Append("Snapshots").Append(base::mac::BaseBundleID());
44 if (base::ios::IsRunningOnIOS8OrLater()) {
45 // On iOS8, the snapshots are located in a path with the bundle ID used
47 snapshotsDir = snapshotsDir.Append(base::mac::BaseBundleID());
49 // On iOS7, the snapshots are located in the subfolder "Main".
50 snapshotsDir = snapshotsDir.Append("Main");
52 const char* retinaSuffix = "";
53 CGFloat scale = [UIScreen mainScreen].scale;
56 } else if (scale == 3) {
59 for (unsigned int i = 0; i < arraysize(kOrientationDescriptions); i++) {
60 std::string snapshotFilename =
61 base::StringPrintf("UIApplicationAutomaticSnapshotDefault-%s%s.png",
62 kOrientationDescriptions[i], retinaSuffix);
63 base::FilePath snapshotPath = snapshotsDir.Append(snapshotFilename);
64 snapshotsPaths->push_back(snapshotPath);