namespace {
+// Return the path constant from string.
+int GetPathConstant(const std::string& name) {
+ if (name == "appData")
+ return brightray::DIR_APP_DATA;
+ else if (name == "userData")
+ return brightray::DIR_USER_DATA;
+ else
+ return -1;
+}
+
class ResolveProxyHelper {
public:
ResolveProxyHelper(const GURL& url, App::ResolveProxyCallback callback)
Emit("ready");
}
-void App::SetDataPath(const base::FilePath& path) {
- PathService::Override(brightray::DIR_USER_DATA, path);
-}
-
-base::FilePath App::GetDataPath() {
+base::FilePath App::GetPath(const std::string& name) {
base::FilePath path;
- PathService::Get(brightray::DIR_USER_DATA, &path);
+ int key = GetPathConstant(name);
+ if (key >= 0)
+ PathService::Get(key, &path);
return path;
}
+void App::SetPath(const std::string& name, const base::FilePath& path) {
+ int key = GetPathConstant(name);
+ if (key >= 0)
+ PathService::Override(key, path);
+}
+
void App::ResolveProxy(const GURL& url, ResolveProxyCallback callback) {
new ResolveProxyHelper(url, callback);
}
.SetMethod("setUserTasks",
base::Bind(&Browser::SetUserTasks, browser))
#endif
- .SetMethod("setDataPath", &App::SetDataPath)
- .SetMethod("getDataPath", &App::GetDataPath)
+ .SetMethod("setPath", &App::SetPath)
+ .SetMethod("getPath", &App::GetPath)
.SetMethod("resolveProxy", &App::ResolveProxy)
.SetMethod("setDesktopName", &App::SetDesktopName);
}
v8::Isolate* isolate) override;
private:
+ // Get/Set the pre-defined path in PathService.
+ base::FilePath GetPath(const std::string& name);
+ void SetPath(const std::string& name, const base::FilePath& path);
+
void SetDataPath(const base::FilePath& path);
base::FilePath GetDataPath();
void ResolveProxy(const GURL& url, ResolveProxyCallback callback);