Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / xwalk / experimental / native_file_system / virtual_root_provider_linux.cc
1 // Copyright (c) 2014 Intel Corporation. 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 "xwalk/experimental/native_file_system/virtual_root_provider.h"
6
7 #include <map>
8 #include <string>
9
10 #include "base/files/file_path.h"
11 #include "base/files/file_util.h"
12
13 bool VirtualRootProvider::testing_enabled_ = false;
14
15 VirtualRootProvider::VirtualRootProvider() {
16   if (!virtual_root_map_.empty())
17     return;
18
19   if (testing_enabled_) {
20     base::GetTempDir(&home_path_);
21   } else {
22     home_path_ = base::GetHomeDir();
23   }
24
25   // TODO(shawngao5): Hard code virtual root mapping for linux here.
26   // In future, it should be removed by parsing xdg configure file for
27   // user direcory.
28   virtual_root_map_["DESKTOP"] = home_path_.Append("Desktop");
29   virtual_root_map_["DOWNLOADS"] = home_path_.Append("Downloads");
30   virtual_root_map_["DOCUMENTS"] = home_path_.Append("Documents");
31   virtual_root_map_["MUSIC"] = home_path_.Append("Music");
32   virtual_root_map_["PICTURES"] = home_path_.Append("Pictures");
33   virtual_root_map_["VIDEOS"] = home_path_.Append("Videos");
34 }
35
36 void VirtualRootProvider::SetTesting(bool testing_enabled) {
37   testing_enabled_ = testing_enabled;
38   base::FilePath tmp_path;
39   base::GetTempDir(&tmp_path);
40   base::FilePath doc_path = tmp_path.Append("Documents");
41   if (!DirectoryExists(doc_path)) {
42     CreateDirectory(doc_path);
43   }
44 }