Skip to content

Commit

Permalink
Files.app: Use quotaBytesUsedAggregate to know the actual available s…
Browse files Browse the repository at this point in the history
…pace.

We need to use quotaBytesUsedAggregate to know the actual available space, because the current quotaBytesUsed returns usage in only Google Drive (doesn't include Gmail, G+ Photos, etc...).
https://developers.google.com/drive/v2/reference/about#resource

BUG=483058
TEST=run unit_tests

Review URL: https://codereview.chromium.org/1125123008

Cr-Commit-Position: refs/heads/master@{#329330}
  • Loading branch information
fukino authored and Commit bot committed May 12, 2015
1 parent 02d9aea commit fa39c65
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 23 deletions.
5 changes: 2 additions & 3 deletions chrome/browser/chromeos/drive/file_system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -712,9 +712,8 @@ void FileSystem::OnGetAboutResource(
}
DCHECK(about_resource);

callback.Run(FILE_ERROR_OK,
about_resource->quota_bytes_total(),
about_resource->quota_bytes_used());
callback.Run(FILE_ERROR_OK, about_resource->quota_bytes_total(),
about_resource->quota_bytes_used_aggregate());
}

void FileSystem::GetShareUrl(const base::FilePath& file_path,
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/drive/drive_api_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const int kMaxNumFilesResourcePerRequestForSearch = 100;

// For performance, we declare all fields we use.
const char kAboutResourceFields[] =
"kind,quotaBytesTotal,quotaBytesUsed,largestChangeId,rootFolderId";
"kind,quotaBytesTotal,quotaBytesUsedAggregate,largestChangeId,rootFolderId";
const char kFileResourceFields[] =
"kind,id,title,createdDate,sharedWithMeDate,mimeType,"
"md5Checksum,fileSize,labels/trashed,imageMediaMetadata/width,"
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/drive/fake_drive_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ FakeDriveService::FakeDriveService()
weak_ptr_factory_(this) {
about_resource_->set_largest_change_id(654321);
about_resource_->set_quota_bytes_total(9876543210);
about_resource_->set_quota_bytes_used(6789012345);
about_resource_->set_quota_bytes_used_aggregate(6789012345);
about_resource_->set_root_folder_id(GetRootResourceId());
}

Expand Down Expand Up @@ -326,7 +326,7 @@ bool FakeDriveService::HasApp(const std::string& app_id) const {
void FakeDriveService::SetQuotaValue(int64 used, int64 total) {
DCHECK(thread_checker_.CalledOnValidThread());

about_resource_->set_quota_bytes_used(used);
about_resource_->set_quota_bytes_used_aggregate(used);
about_resource_->set_quota_bytes_total(total);
}

Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/ui/webui/chromeos/drive_internals_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ void DriveInternalsWebUIHandler::OnGetAboutResource(
about_resource.SetDouble("account-quota-total",
parsed_about_resource->quota_bytes_total());
about_resource.SetDouble("account-quota-used",
parsed_about_resource->quota_bytes_used());
parsed_about_resource->quota_bytes_used_aggregate());
about_resource.SetDouble("account-largest-changestamp-remote",
parsed_about_resource->largest_change_id());
about_resource.SetString("root-resource-id",
Expand Down
2 changes: 1 addition & 1 deletion chrome/test/data/drive/about.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"selfLink": "https://www.googleapis.com/drive/v2/about",
"name": "Test User",
"quotaBytesTotal": "5368709120",
"quotaBytesUsed": "1073741824",
"quotaBytesUsedAggregate": "1073741824",
"quotaBytesUsedInTrash": "0",
"largestChangeId": "8177",
"rootFolderId": "0AIv7G8yEYAWHUk9123",
Expand Down
11 changes: 6 additions & 5 deletions google_apis/drive/drive_api_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const char kLargestChangeId[] = "largestChangeId";
// https://developers.google.com/drive/v2/reference/about
const char kAboutKind[] = "drive#about";
const char kQuotaBytesTotal[] = "quotaBytesTotal";
const char kQuotaBytesUsed[] = "quotaBytesUsed";
const char kQuotaBytesUsedAggregate[] = "quotaBytesUsedAggregate";
const char kRootFolderId[] = "rootFolderId";

// App Icon
Expand Down Expand Up @@ -209,7 +209,7 @@ bool IsResourceKindExpected(const base::Value& value,
AboutResource::AboutResource()
: largest_change_id_(0),
quota_bytes_total_(0),
quota_bytes_used_(0) {}
quota_bytes_used_aggregate_(0) {}

AboutResource::~AboutResource() {}

Expand All @@ -232,9 +232,10 @@ void AboutResource::RegisterJSONConverter(
converter->RegisterCustomField<int64>(kQuotaBytesTotal,
&AboutResource::quota_bytes_total_,
&base::StringToInt64);
converter->RegisterCustomField<int64>(kQuotaBytesUsed,
&AboutResource::quota_bytes_used_,
&base::StringToInt64);
converter->RegisterCustomField<int64>(
kQuotaBytesUsedAggregate,
&AboutResource::quota_bytes_used_aggregate_,
&base::StringToInt64);
converter->RegisterStringField(kRootFolderId,
&AboutResource::root_folder_id_);
}
Expand Down
10 changes: 6 additions & 4 deletions google_apis/drive/drive_api_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ class AboutResource {
// Returns total number of quota bytes.
int64 quota_bytes_total() const { return quota_bytes_total_; }
// Returns the number of quota bytes used.
int64 quota_bytes_used() const { return quota_bytes_used_; }
int64 quota_bytes_used_aggregate() const {
return quota_bytes_used_aggregate_;
}
// Returns root folder ID.
const std::string& root_folder_id() const { return root_folder_id_; }

Expand All @@ -58,8 +60,8 @@ class AboutResource {
void set_quota_bytes_total(int64 quota_bytes_total) {
quota_bytes_total_ = quota_bytes_total;
}
void set_quota_bytes_used(int64 quota_bytes_used) {
quota_bytes_used_ = quota_bytes_used;
void set_quota_bytes_used_aggregate(int64 quota_bytes_used_aggregate) {
quota_bytes_used_aggregate_ = quota_bytes_used_aggregate;
}
void set_root_folder_id(const std::string& root_folder_id) {
root_folder_id_ = root_folder_id;
Expand All @@ -75,7 +77,7 @@ class AboutResource {

int64 largest_change_id_;
int64 quota_bytes_total_;
int64 quota_bytes_used_;
int64 quota_bytes_used_aggregate_;
std::string root_folder_id_;

// This class is copyable on purpose.
Expand Down
2 changes: 1 addition & 1 deletion google_apis/drive/drive_api_parser_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ TEST(DriveAPIParserTest, AboutResourceParser) {

EXPECT_EQ("0AIv7G8yEYAWHUk9123", resource->root_folder_id());
EXPECT_EQ(5368709120LL, resource->quota_bytes_total());
EXPECT_EQ(1073741824LL, resource->quota_bytes_used());
EXPECT_EQ(1073741824LL, resource->quota_bytes_used_aggregate());
EXPECT_EQ(8177LL, resource->largest_change_id());
}

Expand Down
12 changes: 7 additions & 5 deletions google_apis/drive/drive_api_requests_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -496,16 +496,16 @@ TEST_F(DriveApiRequestsTest, DriveApiDataRequest_Fields) {
test_util::CreateQuitCallback(
&run_loop,
test_util::CreateCopyResultCallback(&error, &about_resource)));
request->set_fields(
"kind,quotaBytesTotal,quotaBytesUsed,largestChangeId,rootFolderId");
request->set_fields("kind,quotaBytesTotal,quotaBytesUsedAggregate,"
"largestChangeId,rootFolderId");
request_sender_->StartRequestWithRetry(request);
run_loop.Run();
}

EXPECT_EQ(HTTP_SUCCESS, error);
EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method);
EXPECT_EQ("/drive/v2/about?"
"fields=kind%2CquotaBytesTotal%2CquotaBytesUsed%2C"
"fields=kind%2CquotaBytesTotal%2CquotaBytesUsedAggregate%2C"
"largestChangeId%2CrootFolderId",
http_request_.relative_url);

Expand All @@ -515,7 +515,8 @@ TEST_F(DriveApiRequestsTest, DriveApiDataRequest_Fields) {
ASSERT_TRUE(about_resource.get());
EXPECT_EQ(expected->largest_change_id(), about_resource->largest_change_id());
EXPECT_EQ(expected->quota_bytes_total(), about_resource->quota_bytes_total());
EXPECT_EQ(expected->quota_bytes_used(), about_resource->quota_bytes_used());
EXPECT_EQ(expected->quota_bytes_used_aggregate(),
about_resource->quota_bytes_used_aggregate());
EXPECT_EQ(expected->root_folder_id(), about_resource->root_folder_id());
}

Expand Down Expand Up @@ -666,7 +667,8 @@ TEST_F(DriveApiRequestsTest, AboutGetRequest_ValidJson) {
ASSERT_TRUE(about_resource.get());
EXPECT_EQ(expected->largest_change_id(), about_resource->largest_change_id());
EXPECT_EQ(expected->quota_bytes_total(), about_resource->quota_bytes_total());
EXPECT_EQ(expected->quota_bytes_used(), about_resource->quota_bytes_used());
EXPECT_EQ(expected->quota_bytes_used_aggregate(),
about_resource->quota_bytes_used_aggregate());
EXPECT_EQ(expected->root_folder_id(), about_resource->root_folder_id());
}

Expand Down

0 comments on commit fa39c65

Please sign in to comment.