Commit 7cca8356 authored by Julian Pastarmov's avatar Julian Pastarmov Committed by Commit Bot

Adjust the setDeviceData API paths on linux to match the native host

Replace .cache with .config.

BUG=none

Change-Id: Ie801e3980adebcfd0514e60b42a82b06a30a1cf1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2051125Reviewed-by: default avatarOwen Min <zmin@chromium.org>
Reviewed-by: default avatarGustavo Sacomoto <sacomoto@chromium.org>
Commit-Queue: Julian Pastarmov <pastarmovj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#742589}
parent b0dfec84
......@@ -13,6 +13,7 @@
#include "base/base_paths.h"
#include "base/files/file_util.h"
#include "base/json/json_writer.h"
#include "base/lazy_instance.h"
#include "base/path_service.h"
#include "base/rand_util.h"
#include "base/strings/utf_string_conversions.h"
......@@ -39,6 +40,11 @@
#include "base/win/registry.h"
#endif
#if defined(OS_LINUX)
#include "base/environment.h"
#include "base/nix/xdg_util.h"
#endif
#if defined(OS_MACOSX)
#include "crypto/apple_keychain.h"
#endif
......@@ -366,20 +372,34 @@ std::string ReadEncryptedSecret() {
#endif // defined(OS_MACOSX)
base::FilePath* GetEndpointVerificationDirOverride() {
static base::NoDestructor<base::FilePath> dir_override;
return dir_override.get();
}
// Returns "AppData\Local\Google\Endpoint Verification".
base::FilePath GetEndpointVerificationDir() {
base::FilePath path;
if (!GetEndpointVerificationDirOverride()->empty())
return *GetEndpointVerificationDirOverride();
#if defined(OS_WIN)
if (!base::PathService::Get(base::DIR_LOCAL_APP_DATA, &path))
#elif defined(OS_LINUX)
if (!base::PathService::Get(base::DIR_CACHE, &path))
std::unique_ptr<base::Environment> env(base::Environment::Create());
path = base::nix::GetXDGDirectory(env.get(), base::nix::kXdgConfigHomeEnvVar,
base::nix::kDotConfigDir);
if (path.empty())
#elif defined(OS_MACOSX)
if (!base::PathService::Get(base::DIR_APP_DATA, &path))
#else
if (true)
#endif
return path;
#if defined(OS_LINUX)
path = path.AppendASCII("google");
#else
path = path.AppendASCII("Google");
#endif
path = path.AppendASCII("Endpoint Verification");
return path;
}
......@@ -420,6 +440,11 @@ GenerateChromeDesktopReportRequest(const base::DictionaryValue& report,
return request;
}
// Sets the path used to store Endpoint Verification data for tests.
void OverrideEndpointVerificationDirForTesting(const base::FilePath& path) {
*GetEndpointVerificationDirOverride() = path;
}
void StoreDeviceData(const std::string& id,
const std::unique_ptr<std::vector<uint8_t>> data,
base::OnceCallback<void(bool)> callback) {
......
......@@ -10,6 +10,7 @@
#include <vector>
#include "base/callback.h"
#include "base/files/file_path.h"
#include "components/policy/proto/device_management_backend.pb.h"
class Profile;
......@@ -26,6 +27,9 @@ std::unique_ptr<enterprise_management::ChromeDesktopReportRequest>
GenerateChromeDesktopReportRequest(const base::DictionaryValue& report,
Profile* profile);
// Override the path where Endpoint Verification data is stored for tests.
void OverrideEndpointVerificationDirForTesting(const base::FilePath& path);
// Store the |data| associated with the identifier |id|. Calls |callback| on
// completion with true on success.
void StoreDeviceData(const std::string& id,
......
......@@ -10,6 +10,7 @@
#include "base/path_service.h"
#include "base/strings/stringprintf.h"
#include "build/build_config.h"
#include "chrome/browser/extensions/api/enterprise_reporting_private/chrome_desktop_report_request_helper.h"
#include "chrome/browser/extensions/extension_api_unittest.h"
#include "chrome/browser/extensions/extension_function_test_utils.h"
#include "chrome/browser/policy/fake_browser_dm_token_storage.h"
......@@ -170,15 +171,7 @@ class EnterpriseReportingPrivateDeviceDataFunctionsTest
void SetUp() override {
ExtensionApiUnittest::SetUp();
ASSERT_TRUE(fake_appdata_dir_.CreateUniqueTempDir());
#if defined(OS_WIN)
base::PathService::Override(base::DIR_LOCAL_APP_DATA,
fake_appdata_dir_.GetPath());
#elif defined(OS_LINUX)
base::PathService::Override(base::DIR_CACHE, fake_appdata_dir_.GetPath());
#elif defined(OS_MACOSX)
base::PathService::Override(base::DIR_APP_DATA,
fake_appdata_dir_.GetPath());
#endif
OverrideEndpointVerificationDirForTesting(fake_appdata_dir_.GetPath());
}
private:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment