Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / sync_file_system / drive_backend / drive_backend_util.h
blob4702994ab877761e5565970b6b6cecab67f59427
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 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_DRIVE_BACKEND_UTIL_H_
6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_DRIVE_BACKEND_UTIL_H_
8 #include <string>
10 #include "base/bind.h"
11 #include "base/callback.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.pb.h"
14 #include "chrome/browser/sync_file_system/sync_status_code.h"
15 #include "google_apis/drive/drive_api_error_codes.h"
16 #include "storage/browser/blob/scoped_file.h"
18 namespace google_apis {
19 class ChangeResource;
20 class FileResource;
23 namespace sync_file_system {
24 namespace drive_backend {
26 class LevelDBWrapper;
28 void PutVersionToDB(int64 version, LevelDBWrapper* db);
30 void PutServiceMetadataToDB(const ServiceMetadata& service_metadata,
31 LevelDBWrapper* db);
32 void PutFileMetadataToDB(const FileMetadata& file, LevelDBWrapper* db);
33 void PutFileTrackerToDB(const FileTracker& tracker, LevelDBWrapper* db);
35 void PutFileMetadataDeletionToDB(const std::string& file_id,
36 LevelDBWrapper* db);
37 void PutFileTrackerDeletionToDB(int64 tracker_id, LevelDBWrapper* db);
39 bool HasFileAsParent(const FileDetails& details, const std::string& file_id);
41 bool IsAppRoot(const FileTracker& tracker);
43 std::string GetTrackerTitle(const FileTracker& tracker);
45 SyncStatusCode DriveApiErrorCodeToSyncStatusCode(
46 google_apis::DriveApiErrorCode error);
48 // Returns true if |str| starts with |prefix|, and removes |prefix| from |str|.
49 // If |out| is not NULL, the result is stored in it.
50 bool RemovePrefix(const std::string& str, const std::string& prefix,
51 std::string* out);
53 scoped_ptr<ServiceMetadata> InitializeServiceMetadata(LevelDBWrapper* db);
55 template <typename Src, typename Dest>
56 void AppendContents(const Src& src, Dest* dest) {
57 dest->insert(dest->end(), src.begin(), src.end());
60 template <typename Container>
61 const typename Container::mapped_type& LookUpMap(
62 const Container& container,
63 const typename Container::key_type& key,
64 const typename Container::mapped_type& default_value) {
65 typename Container::const_iterator found = container.find(key);
66 if (found == container.end())
67 return default_value;
68 return found->second;
71 template <typename R, typename S, typename T>
72 R ComposeFunction(const base::Callback<T()>& g,
73 const base::Callback<R(S)>& f) {
74 return f.Run(g.Run());
77 template <typename R, typename S, typename T>
78 base::Callback<R()> CreateComposedFunction(
79 const base::Callback<T()>& g,
80 const base::Callback<R(S)>& f) {
81 return base::Bind(&ComposeFunction<R, S, T>, g, f);
84 } // namespace drive_backend
85 } // namespace sync_file_system
87 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_DRIVE_BACKEND_UTIL_H_