| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "ios/chrome/browser/ui/snapshots_util.h" | |
| 6 | |
| 7 #import <UIKit/UIKit.h> | |
| 8 | |
| 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" | |
| 16 | |
| 17 namespace { | |
| 18 const char* kOrientationDescriptions[] = { | |
| 19 "LandscapeLeft", | |
| 20 "LandscapeRight", | |
| 21 "Portrait", | |
| 22 "PortraitUpsideDown", | |
| 23 }; | |
| 24 } // namespace | |
| 25 | |
| 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( | |
| 33 FROM_HERE, | |
| 34 base::Bind(base::IgnoreResult(&base::DeleteFile), snapshotPath, false)); | |
| 35 } | |
| 36 } | |
| 37 | |
| 38 void GetSnapshotsPaths(std::vector<base::FilePath>* snapshotsPaths) { | |
| 39 DCHECK(snapshotsPaths); | |
| 40 base::FilePath snapshotsDir; | |
| 41 PathService::Get(base::DIR_CACHE, &snapshotsDir); | |
| 42 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 | |
| 46 // twice. | |
| 47 snapshotsDir = snapshotsDir.Append(base::mac::BaseBundleID()); | |
| 48 } else { | |
| 49 // On iOS7, the snapshots are located in the subfolder "Main". | |
| 50 snapshotsDir = snapshotsDir.Append("Main"); | |
| 51 } | |
| 52 const char* retinaSuffix = ""; | |
| 53 CGFloat scale = [UIScreen mainScreen].scale; | |
| 54 if (scale == 2) { | |
| 55 retinaSuffix = "@2x"; | |
| 56 } else if (scale == 3) { | |
| 57 retinaSuffix = "@3x"; | |
| 58 } | |
| 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); | |
| 65 } | |
| 66 } | |
| OLD | NEW |