Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(245)

Unified Diff: runtime/embedders/android/resource.h

Issue 11823034: Backport some work from sample to embedder: (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/embedders/android/main.cc ('k') | runtime/embedders/android/sound_service.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/embedders/android/resource.h
===================================================================
--- runtime/embedders/android/resource.h (revision 16869)
+++ runtime/embedders/android/resource.h (working copy)
@@ -17,7 +17,7 @@
asset_(NULL),
descriptor_(-1),
start_(0),
- length_(0) {
+ length_(-1) {
}
const char* path() {
@@ -25,7 +25,14 @@
}
int32_t descriptor() {
- return descriptor_;
+ if (Open() == 0) {
+ descriptor_ = AAsset_openFileDescriptor(asset_, &start_, &length_);
+ LOGI("%s has start %d, length %d, fd %d",
+ path_, static_cast<int>(start_), static_cast<int>(length_),
+ descriptor_);
+ return descriptor_;
+ }
+ return -1;
}
off_t start() {
@@ -33,29 +40,30 @@
}
off_t length() {
+ if (length_ < 0) {
+ length_ = AAsset_getLength(asset_);
+ }
return length_;
}
- int32_t open() {
+ int32_t Open() {
+ LOGI("Attempting to open asset %s", path_);
asset_ = AAssetManager_open(asset_manager_, path_, AASSET_MODE_UNKNOWN);
if (asset_ != NULL) {
- descriptor_ = AAsset_openFileDescriptor(asset_, &start_, &length_);
- LOGI("%s has start %d, length %d, fd %d",
- path_, static_cast<int>(start_),
- static_cast<int>(length_), descriptor_);
return 0;
}
+ LOGE("Could not open asset %s", path_);
return -1;
}
- void close() {
+ void Close() {
if (asset_ != NULL) {
AAsset_close(asset_);
asset_ = NULL;
}
}
- int32_t read(void* buffer, size_t count) {
+ int32_t Read(void* buffer, size_t count) {
size_t actual = AAsset_read(asset_, buffer, count);
return (actual == count) ? 0 : -1;
}
« no previous file with comments | « runtime/embedders/android/main.cc ('k') | runtime/embedders/android/sound_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698