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
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/extensions/file_manager/private_api_misc.h"
7 #include "base/files/file_path.h"
8 #include "base/prefs/pref_service.h"
9 #include "base/values.h"
10 #include "chrome/browser/chromeos/drive/drive_integration_service.h"
11 #include "chrome/browser/chromeos/drive/logging.h"
12 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h"
13 #include "chrome/browser/chromeos/settings/cros_settings.h"
14 #include "chrome/browser/lifetime/application_lifetime.h"
15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/common/pref_names.h"
17 #include "content/public/browser/render_view_host.h"
18 #include "content/public/common/page_zoom.h"
21 namespace file_manager
{
23 LogoutUserFunction::LogoutUserFunction() {
26 LogoutUserFunction::~LogoutUserFunction() {
29 bool LogoutUserFunction::RunImpl() {
30 chrome::AttemptUserExit();
34 GetPreferencesFunction::GetPreferencesFunction() {
37 GetPreferencesFunction::~GetPreferencesFunction() {
40 bool GetPreferencesFunction::RunImpl() {
41 scoped_ptr
<DictionaryValue
> value(new DictionaryValue());
43 const PrefService
* service
= profile_
->GetPrefs();
45 value
->SetBoolean("driveEnabled",
46 drive::util::IsDriveEnabledForProfile(profile_
));
48 value
->SetBoolean("cellularDisabled",
49 service
->GetBoolean(prefs::kDisableDriveOverCellular
));
51 value
->SetBoolean("hostedFilesDisabled",
52 service
->GetBoolean(prefs::kDisableDriveHostedFiles
));
54 value
->SetBoolean("use24hourClock",
55 service
->GetBoolean(prefs::kUse24HourClock
));
59 if (!chromeos::CrosSettings::Get()->GetBoolean(
60 chromeos::kAllowRedeemChromeOsRegistrationOffers
, &allow
)) {
63 value
->SetBoolean("allowRedeemOffers", allow
);
66 SetResult(value
.release());
68 drive::util::Log(logging::LOG_INFO
, "%s succeeded.", name().c_str());
72 SetPreferencesFunction::SetPreferencesFunction() {
75 SetPreferencesFunction::~SetPreferencesFunction() {
78 bool SetPreferencesFunction::RunImpl() {
79 base::DictionaryValue
* value
= NULL
;
81 if (!args_
->GetDictionary(0, &value
) || !value
)
84 PrefService
* service
= profile_
->GetPrefs();
88 if (value
->GetBoolean("cellularDisabled", &tmp
))
89 service
->SetBoolean(prefs::kDisableDriveOverCellular
, tmp
);
91 if (value
->GetBoolean("hostedFilesDisabled", &tmp
))
92 service
->SetBoolean(prefs::kDisableDriveHostedFiles
, tmp
);
94 drive::util::Log(logging::LOG_INFO
, "%s succeeded.", name().c_str());
98 ZipSelectionFunction::ZipSelectionFunction() {
101 ZipSelectionFunction::~ZipSelectionFunction() {
104 bool ZipSelectionFunction::RunImpl() {
105 if (args_
->GetSize() < 3) {
109 // First param is the source directory URL.
111 if (!args_
->GetString(0, &dir_url
) || dir_url
.empty())
114 base::FilePath src_dir
= util::GetLocalPathFromURL(
115 render_view_host(), profile(), GURL(dir_url
));
119 // Second param is the list of selected file URLs.
120 ListValue
* selection_urls
= NULL
;
121 args_
->GetList(1, &selection_urls
);
122 if (!selection_urls
|| !selection_urls
->GetSize())
125 std::vector
<base::FilePath
> files
;
126 for (size_t i
= 0; i
< selection_urls
->GetSize(); ++i
) {
127 std::string file_url
;
128 selection_urls
->GetString(i
, &file_url
);
129 base::FilePath path
= util::GetLocalPathFromURL(
130 render_view_host(), profile(), GURL(file_url
));
133 files
.push_back(path
);
136 // Third param is the name of the output zip file.
137 std::string dest_name
;
138 if (!args_
->GetString(2, &dest_name
) || dest_name
.empty())
141 // Check if the dir path is under Drive mount point.
142 // TODO(hshi): support create zip file on Drive (crbug.com/158690).
143 if (drive::util::IsUnderDriveMountPoint(src_dir
))
146 base::FilePath dest_file
= src_dir
.Append(dest_name
);
147 std::vector
<base::FilePath
> src_relative_paths
;
148 for (size_t i
= 0; i
!= files
.size(); ++i
) {
149 const base::FilePath
& file_path
= files
[i
];
151 // Obtain the relative path of |file_path| under |src_dir|.
152 base::FilePath relative_path
;
153 if (!src_dir
.AppendRelativePath(file_path
, &relative_path
))
155 src_relative_paths
.push_back(relative_path
);
158 zip_file_creator_
= new ZipFileCreator(this,
163 // Keep the refcount until the zipping is complete on utility process.
166 zip_file_creator_
->Start();
170 void ZipSelectionFunction::OnZipDone(bool success
) {
171 SetResult(new base::FundamentalValue(success
));
176 ZoomFunction::ZoomFunction() {
179 ZoomFunction::~ZoomFunction() {
182 bool ZoomFunction::RunImpl() {
183 content::RenderViewHost
* const view_host
= render_view_host();
184 std::string operation
;
185 args_
->GetString(0, &operation
);
186 content::PageZoom zoom_type
;
187 if (operation
== "in") {
188 zoom_type
= content::PAGE_ZOOM_IN
;
189 } else if (operation
== "out") {
190 zoom_type
= content::PAGE_ZOOM_OUT
;
191 } else if (operation
== "reset") {
192 zoom_type
= content::PAGE_ZOOM_RESET
;
197 view_host
->Zoom(zoom_type
);
201 } // namespace file_manager